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 // 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(); |
| 26 } |
| 27 |
| 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(); |
| 38 } |
| 39 |
| 40 class RuntimeDataTest : public testing::Test { |
| 41 public: |
| 42 RuntimeDataTest() : runtime_data_(®istry_) {} |
| 43 virtual ~RuntimeDataTest() {} |
| 44 |
| 45 protected: |
| 46 ExtensionRegistry registry_; |
| 47 RuntimeData runtime_data_; |
| 48 |
| 49 private: |
| 50 DISALLOW_COPY_AND_ASSIGN(RuntimeDataTest); |
| 51 }; |
| 52 |
| 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)); |
| 57 |
| 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)); |
| 62 |
| 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)); |
| 68 } |
| 69 |
| 70 TEST_F(RuntimeDataTest, IsBeingUpgraded) { |
| 71 scoped_refptr<Extension> extension = CreateExtension(); |
| 72 |
| 73 // An extension is not being upgraded until the flag is set. |
| 74 EXPECT_FALSE(runtime_data_.IsBeingUpgraded(extension)); |
| 75 |
| 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)); |
| 81 } |
| 82 |
| 83 // TODO(mpcomplete): Remove. http://crbug.com/100411 |
| 84 TEST_F(RuntimeDataTest, HasUsedWebRequest) { |
| 85 scoped_refptr<Extension> extension = CreateExtension(); |
| 86 |
| 87 // An extension has not used web request until the flag is set. |
| 88 EXPECT_FALSE(runtime_data_.HasUsedWebRequest(extension)); |
| 89 |
| 90 // The flag can be toggled. |
| 91 runtime_data_.SetHasUsedWebRequest(extension, true); |
| 92 EXPECT_TRUE(runtime_data_.HasUsedWebRequest(extension)); |
| 93 runtime_data_.SetHasUsedWebRequest(extension, false); |
| 94 EXPECT_FALSE(runtime_data_.HasUsedWebRequest(extension)); |
| 95 } |
| 96 |
| 97 // Unloading an extension stops tracking it. |
| 98 TEST_F(RuntimeDataTest, OnExtensionUnloaded) { |
| 99 scoped_refptr<Extension> extension = CreateExtensionWithBackgroundPage(); |
| 100 runtime_data_.SetBackgroundPageReady(extension, true); |
| 101 ASSERT_TRUE(runtime_data_.HasExtensionForTesting(extension)); |
| 102 |
| 103 runtime_data_.OnExtensionUnloaded(extension); |
| 104 EXPECT_FALSE(runtime_data_.HasExtensionForTesting(extension)); |
| 105 } |
| 106 |
| 107 } // namespace |
| 108 } // namespace extensions |
OLD | NEW |