summaryrefslogtreecommitdiffstats
path: root/extensions/common/extension_set_unittest.cc
diff options
context:
space:
mode:
authorrdevlin.cronin@chromium.org <rdevlin.cronin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-17 03:26:57 +0000
committerrdevlin.cronin@chromium.org <rdevlin.cronin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-17 03:26:57 +0000
commit289c44bbf904e0339b8e4b0d8ed5456593a135e5 (patch)
tree2fae601f2a44ade6701c4e1a233e734579606f59 /extensions/common/extension_set_unittest.cc
parent3184a8e64ddcf24c694e8bd57dad40d4011991f1 (diff)
downloadchromium_src-289c44bbf904e0339b8e4b0d8ed5456593a135e5.zip
chromium_src-289c44bbf904e0339b8e4b0d8ed5456593a135e5.tar.gz
chromium_src-289c44bbf904e0339b8e4b0d8ed5456593a135e5.tar.bz2
Move c/c/e/extension_set to top-level extensions/
Move extension_set.h/cc and extension_set_unittest to extensions/common/. Remove unused includes. Add includes where transitive includes were used. Update DEPS. No functional changes. BUG=162530 TBR=sky@chromium.org (c/b/autocomplete, c/b/ui, c/test) TBR=jam@chromium.org (c/b/automation) TBR=atwilson@chromium.org (c/b/background, c/b/sync, c/b/policy) TBR=bauerb@chromium.org (c/b/browsing_data, c/b/content_settings, c/b/managed_mode) TBR=satorux@chromium.org (c/b/chromeos) TBR=yurys@chromium.org (c/b/devtools) TBR=thestig@chromium.org (c/b/media_galleries) TBR=stevenjb@chromium.org (c/b/notifications) TBR=battre@chromium.org (c/b/profile_resetter) TBR=dmazzoni@chromium.org (c/b/speech) TBR=kinuko@chromium.org (c/b/sync_file_system) TBR=pkotwicz@chromium.org (c/b/themes) Review URL: https://codereview.chromium.org/102103005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@241131 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'extensions/common/extension_set_unittest.cc')
-rw-r--r--extensions/common/extension_set_unittest.cc142
1 files changed, 142 insertions, 0 deletions
diff --git a/extensions/common/extension_set_unittest.cc b/extensions/common/extension_set_unittest.cc
new file mode 100644
index 0000000..75a69de
--- /dev/null
+++ b/extensions/common/extension_set_unittest.cc
@@ -0,0 +1,142 @@
+// Copyright 2013 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 "base/files/file_path.h"
+#include "base/logging.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/values.h"
+#include "extensions/common/extension.h"
+#include "extensions/common/extension_set.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace extensions {
+
+namespace {
+
+scoped_refptr<Extension> CreateTestExtension(const std::string& name,
+ const std::string& launch_url,
+ const std::string& extent) {
+#if defined(OS_WIN)
+ base::FilePath path(FILE_PATH_LITERAL("c:\\"));
+#else
+ base::FilePath path(FILE_PATH_LITERAL("/"));
+#endif
+ path = path.AppendASCII(name);
+
+ base::DictionaryValue manifest;
+ manifest.SetString("name", name);
+ manifest.SetString("version", "1");
+
+ if (!launch_url.empty())
+ manifest.SetString("app.launch.web_url", launch_url);
+
+ if (!extent.empty()) {
+ base::ListValue* urls = new base::ListValue();
+ manifest.Set("app.urls", urls);
+ urls->Append(new base::StringValue(extent));
+ }
+
+ std::string error;
+ scoped_refptr<Extension> extension(
+ Extension::Create(path, Manifest::INTERNAL, manifest,
+ Extension::NO_FLAGS, &error));
+ EXPECT_TRUE(extension.get()) << error;
+ return extension;
+}
+
+} // namespace
+
+TEST(ExtensionSetTest, ExtensionSet) {
+ scoped_refptr<Extension> ext1(CreateTestExtension(
+ "a", "https://chrome.google.com/launch", "https://chrome.google.com/"));
+
+ scoped_refptr<Extension> ext2(CreateTestExtension(
+ "a", "http://code.google.com/p/chromium",
+ "http://code.google.com/p/chromium/"));
+
+ scoped_refptr<Extension> ext3(CreateTestExtension(
+ "b", "http://dev.chromium.org/", "http://dev.chromium.org/"));
+
+ scoped_refptr<Extension> ext4(
+ CreateTestExtension("c", std::string(), std::string()));
+
+ ASSERT_TRUE(ext1.get() && ext2.get() && ext3.get() && ext4.get());
+
+ ExtensionSet extensions;
+
+ // Add an extension.
+ EXPECT_TRUE(extensions.Insert(ext1));
+ EXPECT_EQ(1u, extensions.size());
+ EXPECT_EQ(ext1, extensions.GetByID(ext1->id()));
+
+ // Since extension2 has same ID, it should overwrite extension1.
+ EXPECT_FALSE(extensions.Insert(ext2));
+ EXPECT_EQ(1u, extensions.size());
+ EXPECT_EQ(ext2, extensions.GetByID(ext1->id()));
+
+ // Add the other extensions.
+ EXPECT_TRUE(extensions.Insert(ext3));
+ EXPECT_TRUE(extensions.Insert(ext4));
+ EXPECT_EQ(3u, extensions.size());
+
+ // Get extension by its chrome-extension:// URL
+ EXPECT_EQ(ext2, extensions.GetExtensionOrAppByURL(
+ ext2->GetResourceURL("test.html")));
+ EXPECT_EQ(ext3, extensions.GetExtensionOrAppByURL(
+ ext3->GetResourceURL("test.html")));
+ EXPECT_EQ(ext4, extensions.GetExtensionOrAppByURL(
+ ext4->GetResourceURL("test.html")));
+
+ // Get extension by web extent.
+ EXPECT_EQ(ext2, extensions.GetExtensionOrAppByURL(
+ GURL("http://code.google.com/p/chromium/monkey")));
+ EXPECT_EQ(ext3, extensions.GetExtensionOrAppByURL(
+ GURL("http://dev.chromium.org/design-docs/")));
+ EXPECT_FALSE(extensions.GetExtensionOrAppByURL(
+ GURL("http://blog.chromium.org/")));
+
+ // Test InSameExtent().
+ EXPECT_TRUE(extensions.InSameExtent(
+ GURL("http://code.google.com/p/chromium/monkey/"),
+ GURL("http://code.google.com/p/chromium/")));
+ EXPECT_FALSE(extensions.InSameExtent(
+ GURL("http://code.google.com/p/chromium/"),
+ GURL("https://code.google.com/p/chromium/")));
+ EXPECT_FALSE(extensions.InSameExtent(
+ GURL("http://code.google.com/p/chromium/"),
+ GURL("http://dev.chromium.org/design-docs/")));
+
+ // Both of these should be NULL, which mean true for InSameExtent.
+ EXPECT_TRUE(extensions.InSameExtent(
+ GURL("http://www.google.com/"),
+ GURL("http://blog.chromium.org/")));
+
+ // Remove one of the extensions.
+ EXPECT_TRUE(extensions.Remove(ext2->id()));
+ EXPECT_EQ(2u, extensions.size());
+ EXPECT_FALSE(extensions.GetByID(ext2->id()));
+
+ // Make a union of a set with 3 more extensions (only 2 are new).
+ scoped_refptr<Extension> ext5(
+ CreateTestExtension("d", std::string(), std::string()));
+ scoped_refptr<Extension> ext6(
+ CreateTestExtension("e", std::string(), std::string()));
+ ASSERT_TRUE(ext5.get() && ext6.get());
+
+ scoped_ptr<ExtensionSet> to_add(new ExtensionSet());
+ // |ext3| is already in |extensions|, should not affect size.
+ EXPECT_TRUE(to_add->Insert(ext3));
+ EXPECT_TRUE(to_add->Insert(ext5));
+ EXPECT_TRUE(to_add->Insert(ext6));
+
+ ASSERT_TRUE(extensions.Contains(ext3->id()));
+ ASSERT_TRUE(extensions.InsertAll(*to_add));
+ EXPECT_EQ(4u, extensions.size());
+
+ ASSERT_FALSE(extensions.InsertAll(*to_add)); // Re-adding same set no-ops.
+ EXPECT_EQ(4u, extensions.size());
+}
+
+} // namespace extensions