OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #include "extensions/browser/runtime_data.h" | |
6 | |
7 #include <string> | |
8 | |
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" | |
15 | |
16 namespace extensions { | |
17 namespace { | |
18 | |
19 typedef testing::Test RuntimeDataTest; | |
20 | |
21 // Creates a very simple extension. | |
22 scoped_refptr<Extension> CreateExtension() { | |
23 return ExtensionBuilder() | |
24 .SetManifest( | |
25 DictionaryBuilder().Set("name", "test").Set("version", "0.1")) | |
26 .SetID("id1") | |
27 .Build(); | |
28 } | |
29 | |
30 // Creates a very simple extension with a background page. | |
31 scoped_refptr<Extension> CreateExtensionWithBackgroundPage() { | |
32 return ExtensionBuilder() | |
33 .SetManifest( | |
34 DictionaryBuilder() | |
35 .Set("name", "test") | |
36 .Set("version", "0.1") | |
37 .Set("background", DictionaryBuilder().Set("page", "bg.html"))) | |
38 .SetID("id2") | |
39 .Build(); | |
40 } | |
41 | |
42 TEST_F(RuntimeDataTest, IsBackgroundPageReady) { | |
43 ExtensionRegistry registry; | |
44 RuntimeData runtime_data(®istry); | |
not at google - send to devlin
2014/01/22 21:08:16
you could do this in a SetUp method if you wanted.
| |
45 | |
46 // An extension without a background page is always considered ready. | |
47 scoped_refptr<Extension> no_background = CreateExtension(); | |
48 EXPECT_TRUE(runtime_data.IsBackgroundPageReady(no_background)); | |
49 | |
50 // An extension with a background page is not ready until the flag is set. | |
51 scoped_refptr<Extension> with_background = | |
52 CreateExtensionWithBackgroundPage(); | |
53 EXPECT_FALSE(runtime_data.IsBackgroundPageReady(with_background)); | |
54 | |
55 // The flag can be toggled. | |
56 runtime_data.SetBackgroundPageReady(with_background, true); | |
57 EXPECT_TRUE(runtime_data.IsBackgroundPageReady(with_background)); | |
58 runtime_data.SetBackgroundPageReady(with_background, false); | |
59 EXPECT_FALSE(runtime_data.IsBackgroundPageReady(with_background)); | |
60 } | |
61 | |
62 TEST_F(RuntimeDataTest, IsBeingUpgraded) { | |
63 ExtensionRegistry registry; | |
64 RuntimeData runtime_data(®istry); | |
65 scoped_refptr<Extension> extension = CreateExtension(); | |
66 | |
67 // An extension is not being upgraded until the flag is set. | |
68 EXPECT_FALSE(runtime_data.IsBeingUpgraded(extension)); | |
69 | |
70 // The flag can be toggled. | |
71 runtime_data.SetBeingUpgraded(extension, true); | |
72 EXPECT_TRUE(runtime_data.IsBeingUpgraded(extension)); | |
73 runtime_data.SetBeingUpgraded(extension, false); | |
74 EXPECT_FALSE(runtime_data.IsBeingUpgraded(extension)); | |
75 } | |
76 | |
77 // TODO(mpcomplete): Remove. http://crbug.com/100411 | |
78 TEST_F(RuntimeDataTest, HasUsedWebRequest) { | |
79 ExtensionRegistry registry; | |
80 RuntimeData runtime_data(®istry); | |
81 scoped_refptr<Extension> extension = CreateExtension(); | |
82 | |
83 // An extension has not used web request until the flag is set. | |
84 EXPECT_FALSE(runtime_data.HasUsedWebRequest(extension)); | |
85 | |
86 // The flag can be toggled. | |
87 runtime_data.SetHasUsedWebRequest(extension, true); | |
88 EXPECT_TRUE(runtime_data.HasUsedWebRequest(extension)); | |
89 runtime_data.SetHasUsedWebRequest(extension, false); | |
90 EXPECT_FALSE(runtime_data.HasUsedWebRequest(extension)); | |
91 } | |
92 | |
93 // Unloading an extension stops tracking it. | |
94 TEST_F(RuntimeDataTest, OnExtensionUnloaded) { | |
95 ExtensionRegistry registry; | |
96 RuntimeData runtime_data(®istry); | |
97 scoped_refptr<Extension> extension = CreateExtensionWithBackgroundPage(); | |
98 runtime_data.SetBackgroundPageReady(extension, true); | |
99 ASSERT_TRUE(runtime_data.HasExtensionForTesting(extension)); | |
100 | |
101 runtime_data.OnExtensionUnloaded(extension); | |
102 EXPECT_FALSE(runtime_data.HasExtensionForTesting(extension)); | |
103 } | |
104 | |
105 } // namespace | |
106 } // namespace extensions | |
OLD | NEW |