summaryrefslogtreecommitdiffstats
path: root/extensions/browser/runtime_data_unittest.cc
diff options
context:
space:
mode:
authorjamescook@chromium.org <jamescook@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-22 23:47:13 +0000
committerjamescook@chromium.org <jamescook@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-22 23:47:13 +0000
commit45f5b7db651f7c508b337a4f0bac3fe917abf214 (patch)
treed2647764dc50e7fb5c4e08f14f9aed696b79fb52 /extensions/browser/runtime_data_unittest.cc
parente18b1c8c81710ae0f97844306969e02b589c3268 (diff)
downloadchromium_src-45f5b7db651f7c508b337a4f0bac3fe917abf214.zip
chromium_src-45f5b7db651f7c508b337a4f0bac3fe917abf214.tar.gz
chromium_src-45f5b7db651f7c508b337a4f0bac3fe917abf214.tar.bz2
app_shell: Extract extension runtime data from ExtensionService
This allows ExtensionHost to use the data when there is no ExtensionService, such as when running app_shell. BUG=332982 TEST=Added unit test, existing extensions browser tests TBR=msw@chromium.org for mechanical change to chrome/browser/ui/views/ Review URL: https://codereview.chromium.org/131743021 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@246449 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'extensions/browser/runtime_data_unittest.cc')
-rw-r--r--extensions/browser/runtime_data_unittest.cc108
1 files changed, 108 insertions, 0 deletions
diff --git a/extensions/browser/runtime_data_unittest.cc b/extensions/browser/runtime_data_unittest.cc
new file mode 100644
index 0000000..207f8aa
--- /dev/null
+++ b/extensions/browser/runtime_data_unittest.cc
@@ -0,0 +1,108 @@
+// 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 {
+
+// 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();
+}
+
+class RuntimeDataTest : public testing::Test {
+ public:
+ RuntimeDataTest() : runtime_data_(&registry_) {}
+ virtual ~RuntimeDataTest() {}
+
+ protected:
+ ExtensionRegistry registry_;
+ RuntimeData runtime_data_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(RuntimeDataTest);
+};
+
+TEST_F(RuntimeDataTest, IsBackgroundPageReady) {
+ // 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) {
+ 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) {
+ 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) {
+ 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