Remove Net.URLRequest_SetReferrer_IsEmptyOrValid histogram.
[chromium-blink-merge.git] / extensions / browser / runtime_data_unittest.cc
blob913aed3293c8ec2820e9c39bce85d1a335aff7e2
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "extensions/browser/runtime_data.h"
7 #include <string>
9 #include "base/memory/ref_counted.h"
10 #include "extensions/browser/extension_registry.h"
11 #include "extensions/common/extension.h"
12 #include "extensions/common/extension_builder.h"
13 #include "extensions/common/value_builder.h"
14 #include "testing/gtest/include/gtest/gtest.h"
16 namespace extensions {
17 namespace {
19 // Creates a very simple extension.
20 scoped_refptr<Extension> CreateExtension() {
21 return ExtensionBuilder()
22 .SetManifest(
23 DictionaryBuilder().Set("name", "test").Set("version", "0.1"))
24 .SetID("id1")
25 .Build();
28 // Creates a very simple extension with a background page.
29 scoped_refptr<Extension> CreateExtensionWithBackgroundPage() {
30 return ExtensionBuilder()
31 .SetManifest(
32 DictionaryBuilder()
33 .Set("name", "test")
34 .Set("version", "0.1")
35 .Set("background", DictionaryBuilder().Set("page", "bg.html")))
36 .SetID("id2")
37 .Build();
40 class RuntimeDataTest : public testing::Test {
41 public:
42 RuntimeDataTest() : registry_(NULL), runtime_data_(&registry_) {}
43 virtual ~RuntimeDataTest() {}
45 protected:
46 ExtensionRegistry registry_;
47 RuntimeData runtime_data_;
49 private:
50 DISALLOW_COPY_AND_ASSIGN(RuntimeDataTest);
53 TEST_F(RuntimeDataTest, IsBackgroundPageReady) {
54 // An extension without a background page is always considered ready.
55 scoped_refptr<Extension> no_background = CreateExtension();
56 EXPECT_TRUE(runtime_data_.IsBackgroundPageReady(no_background));
58 // An extension with a background page is not ready until the flag is set.
59 scoped_refptr<Extension> with_background =
60 CreateExtensionWithBackgroundPage();
61 EXPECT_FALSE(runtime_data_.IsBackgroundPageReady(with_background));
63 // The flag can be toggled.
64 runtime_data_.SetBackgroundPageReady(with_background, true);
65 EXPECT_TRUE(runtime_data_.IsBackgroundPageReady(with_background));
66 runtime_data_.SetBackgroundPageReady(with_background, false);
67 EXPECT_FALSE(runtime_data_.IsBackgroundPageReady(with_background));
70 TEST_F(RuntimeDataTest, IsBeingUpgraded) {
71 scoped_refptr<Extension> extension = CreateExtension();
73 // An extension is not being upgraded until the flag is set.
74 EXPECT_FALSE(runtime_data_.IsBeingUpgraded(extension));
76 // The flag can be toggled.
77 runtime_data_.SetBeingUpgraded(extension, true);
78 EXPECT_TRUE(runtime_data_.IsBeingUpgraded(extension));
79 runtime_data_.SetBeingUpgraded(extension, false);
80 EXPECT_FALSE(runtime_data_.IsBeingUpgraded(extension));
83 TEST_F(RuntimeDataTest, HasUsedWebRequest) {
84 scoped_refptr<Extension> extension = CreateExtension();
86 // An extension has not used web request until the flag is set.
87 EXPECT_FALSE(runtime_data_.HasUsedWebRequest(extension));
89 // The flag can be toggled.
90 runtime_data_.SetHasUsedWebRequest(extension, true);
91 EXPECT_TRUE(runtime_data_.HasUsedWebRequest(extension));
92 runtime_data_.SetHasUsedWebRequest(extension, false);
93 EXPECT_FALSE(runtime_data_.HasUsedWebRequest(extension));
96 // Unloading an extension stops tracking it.
97 TEST_F(RuntimeDataTest, OnExtensionUnloaded) {
98 scoped_refptr<Extension> extension = CreateExtensionWithBackgroundPage();
99 runtime_data_.SetBackgroundPageReady(extension, true);
100 ASSERT_TRUE(runtime_data_.HasExtensionForTesting(extension));
102 runtime_data_.OnExtensionUnloaded(
103 NULL, extension, UnloadedExtensionInfo::REASON_DISABLE);
104 EXPECT_FALSE(runtime_data_.HasExtensionForTesting(extension));
107 } // namespace
108 } // namespace extensions