Chromium Code Reviews| Index: extensions/browser/runtime_data_unittest.cc |
| diff --git a/extensions/browser/runtime_data_unittest.cc b/extensions/browser/runtime_data_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6d73e1d4b2818a1c16cd6512051b6f913a98d045 |
| --- /dev/null |
| +++ b/extensions/browser/runtime_data_unittest.cc |
| @@ -0,0 +1,106 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "extensions/browser/runtime_data.h" |
| + |
| +#include <string> |
| + |
| +#include "base/memory/ref_counted.h" |
| +#include "extensions/browser/extension_registry.h" |
| +#include "extensions/common/extension.h" |
| +#include "extensions/common/extension_builder.h" |
| +#include "extensions/common/value_builder.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace extensions { |
| +namespace { |
| + |
| +typedef testing::Test RuntimeDataTest; |
| + |
| +// Creates a very simple extension. |
| +scoped_refptr<Extension> CreateExtension() { |
| + return ExtensionBuilder() |
| + .SetManifest( |
| + DictionaryBuilder().Set("name", "test").Set("version", "0.1")) |
| + .SetID("id1") |
| + .Build(); |
| +} |
| + |
| +// Creates a very simple extension with a background page. |
| +scoped_refptr<Extension> CreateExtensionWithBackgroundPage() { |
| + return ExtensionBuilder() |
| + .SetManifest( |
| + DictionaryBuilder() |
| + .Set("name", "test") |
| + .Set("version", "0.1") |
| + .Set("background", DictionaryBuilder().Set("page", "bg.html"))) |
| + .SetID("id2") |
| + .Build(); |
| +} |
| + |
| +TEST_F(RuntimeDataTest, IsBackgroundPageReady) { |
| + ExtensionRegistry registry; |
| + 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.
|
| + |
| + // An extension without a background page is always considered ready. |
| + scoped_refptr<Extension> no_background = CreateExtension(); |
| + EXPECT_TRUE(runtime_data.IsBackgroundPageReady(no_background)); |
| + |
| + // An extension with a background page is not ready until the flag is set. |
| + scoped_refptr<Extension> with_background = |
| + CreateExtensionWithBackgroundPage(); |
| + EXPECT_FALSE(runtime_data.IsBackgroundPageReady(with_background)); |
| + |
| + // The flag can be toggled. |
| + runtime_data.SetBackgroundPageReady(with_background, true); |
| + EXPECT_TRUE(runtime_data.IsBackgroundPageReady(with_background)); |
| + runtime_data.SetBackgroundPageReady(with_background, false); |
| + EXPECT_FALSE(runtime_data.IsBackgroundPageReady(with_background)); |
| +} |
| + |
| +TEST_F(RuntimeDataTest, IsBeingUpgraded) { |
| + ExtensionRegistry registry; |
| + RuntimeData runtime_data(®istry); |
| + scoped_refptr<Extension> extension = CreateExtension(); |
| + |
| + // An extension is not being upgraded until the flag is set. |
| + EXPECT_FALSE(runtime_data.IsBeingUpgraded(extension)); |
| + |
| + // The flag can be toggled. |
| + runtime_data.SetBeingUpgraded(extension, true); |
| + EXPECT_TRUE(runtime_data.IsBeingUpgraded(extension)); |
| + runtime_data.SetBeingUpgraded(extension, false); |
| + EXPECT_FALSE(runtime_data.IsBeingUpgraded(extension)); |
| +} |
| + |
| +// TODO(mpcomplete): Remove. http://crbug.com/100411 |
| +TEST_F(RuntimeDataTest, HasUsedWebRequest) { |
| + ExtensionRegistry registry; |
| + RuntimeData runtime_data(®istry); |
| + scoped_refptr<Extension> extension = CreateExtension(); |
| + |
| + // An extension has not used web request until the flag is set. |
| + EXPECT_FALSE(runtime_data.HasUsedWebRequest(extension)); |
| + |
| + // The flag can be toggled. |
| + runtime_data.SetHasUsedWebRequest(extension, true); |
| + EXPECT_TRUE(runtime_data.HasUsedWebRequest(extension)); |
| + runtime_data.SetHasUsedWebRequest(extension, false); |
| + EXPECT_FALSE(runtime_data.HasUsedWebRequest(extension)); |
| +} |
| + |
| +// Unloading an extension stops tracking it. |
| +TEST_F(RuntimeDataTest, OnExtensionUnloaded) { |
| + ExtensionRegistry registry; |
| + RuntimeData runtime_data(®istry); |
| + scoped_refptr<Extension> extension = CreateExtensionWithBackgroundPage(); |
| + runtime_data.SetBackgroundPageReady(extension, true); |
| + ASSERT_TRUE(runtime_data.HasExtensionForTesting(extension)); |
| + |
| + runtime_data.OnExtensionUnloaded(extension); |
| + EXPECT_FALSE(runtime_data.HasExtensionForTesting(extension)); |
| +} |
| + |
| +} // namespace |
| +} // namespace extensions |