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/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; |
| 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; |
| 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; |
| 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 } // namespace |
| 90 } // namespace extensions |
OLD | NEW |