Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(166)

Side by Side Diff: extensions/browser/runtime_data_unittest.cc

Issue 131743021: app_shell: Extract extension runtime data from ExtensionService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: TriggerOnUnloaded (runtime_data) Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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/common/extension.h"
11 #include "extensions/common/extension_builder.h"
12 #include "extensions/common/value_builder.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 namespace extensions {
16 namespace {
17
18 typedef testing::Test RuntimeDataTest;
19
20 // Creates a very simple extension.
21 scoped_refptr<Extension> CreateExtension() {
22 return ExtensionBuilder()
23 .SetManifest(
24 DictionaryBuilder().Set("name", "test").Set("version", "0.1"))
25 .SetID("id1")
26 .Build();
27 }
28
29 // Creates a very simple extension with a background page.
30 scoped_refptr<Extension> CreateExtensionWithBackgroundPage() {
31 return ExtensionBuilder()
32 .SetManifest(
33 DictionaryBuilder()
34 .Set("name", "test")
35 .Set("version", "0.1")
36 .Set("background", DictionaryBuilder().Set("page", "bg.html")))
37 .SetID("id2")
38 .Build();
39 }
40
41 TEST_F(RuntimeDataTest, IsBackgroundPageReady) {
42 RuntimeData runtime_data(NULL);
43
44 // An extension without a background page is always considered ready.
45 scoped_refptr<Extension> no_background = CreateExtension();
46 EXPECT_TRUE(runtime_data.IsBackgroundPageReady(no_background));
47
48 // An extension with a background page is not ready until the flag is set.
49 scoped_refptr<Extension> with_background =
50 CreateExtensionWithBackgroundPage();
51 EXPECT_FALSE(runtime_data.IsBackgroundPageReady(with_background));
52
53 // The flag can be toggled.
54 runtime_data.SetBackgroundPageReady(with_background, true);
55 EXPECT_TRUE(runtime_data.IsBackgroundPageReady(with_background));
56 runtime_data.SetBackgroundPageReady(with_background, false);
57 EXPECT_FALSE(runtime_data.IsBackgroundPageReady(with_background));
58 }
59
60 TEST_F(RuntimeDataTest, IsBeingUpgraded) {
61 RuntimeData runtime_data(NULL);
62 scoped_refptr<Extension> extension = CreateExtension();
63
64 // An extension is not being upgraded until the flag is set.
65 EXPECT_FALSE(runtime_data.IsBeingUpgraded(extension));
66
67 // The flag can be toggled.
68 runtime_data.SetBeingUpgraded(extension, true);
69 EXPECT_TRUE(runtime_data.IsBeingUpgraded(extension));
70 runtime_data.SetBeingUpgraded(extension, false);
71 EXPECT_FALSE(runtime_data.IsBeingUpgraded(extension));
72 }
73
74 // TODO(mpcomplete): Remove. http://crbug.com/100411
75 TEST_F(RuntimeDataTest, HasUsedWebRequest) {
76 RuntimeData runtime_data(NULL);
77 scoped_refptr<Extension> extension = CreateExtension();
78
79 // An extension has not used web request until the flag is set.
80 EXPECT_FALSE(runtime_data.HasUsedWebRequest(extension));
81
82 // The flag can be toggled.
83 runtime_data.SetHasUsedWebRequest(extension, true);
84 EXPECT_TRUE(runtime_data.HasUsedWebRequest(extension));
85 runtime_data.SetHasUsedWebRequest(extension, false);
86 EXPECT_FALSE(runtime_data.HasUsedWebRequest(extension));
87 }
88
89 // Unloading an extension stops tracking it.
90 TEST_F(RuntimeDataTest, OnExtensionUnloaded) {
91 RuntimeData runtime_data(NULL);
92 scoped_refptr<Extension> extension = CreateExtensionWithBackgroundPage();
93 runtime_data.SetBackgroundPageReady(extension, true);
94 ASSERT_TRUE(runtime_data.HasExtensionForTesting(extension));
95
96 runtime_data.OnExtensionUnloaded(extension);
97 EXPECT_FALSE(runtime_data.HasExtensionForTesting(extension));
98 }
99
100 // Disabling an extension resets its background page data.
101 TEST_F(RuntimeDataTest, OnExtensionDisabled) {
102 RuntimeData runtime_data(NULL);
103 scoped_refptr<Extension> extension = CreateExtensionWithBackgroundPage();
104 runtime_data.SetBackgroundPageReady(extension, true);
105 ASSERT_TRUE(runtime_data.IsBackgroundPageReady(extension));
106
107 runtime_data.OnExtensionDisabled(extension);
108 EXPECT_FALSE(runtime_data.IsBackgroundPageReady(extension));
109 }
110
111 } // namespace
112 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698