Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(365)

Unified Diff: chrome/browser/extensions/chrome_info_map_unittest.cc

Issue 473913006: Move InfoMapTest to extensions_unittests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: (info-map) similarity Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/chrome_info_map_unittest.cc
diff --git a/extensions/browser/info_map_unittest.cc b/chrome/browser/extensions/chrome_info_map_unittest.cc
similarity index 43%
copy from extensions/browser/info_map_unittest.cc
copy to chrome/browser/extensions/chrome_info_map_unittest.cc
index 7247706068c485ba319565dd9cd4b5e3cef8b7e9..4a3eb1c0ca02491f1818e0a2d05b1f0ce9de019e 100644
--- a/extensions/browser/info_map_unittest.cc
+++ b/chrome/browser/extensions/chrome_info_map_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// 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.
@@ -15,46 +15,11 @@
using content::BrowserThread;
-namespace keys = extensions::manifest_keys;
-
namespace extensions {
+namespace {
-class InfoMapTest : public testing::Test {
- public:
- InfoMapTest()
- : ui_thread_(BrowserThread::UI, &message_loop_),
- io_thread_(BrowserThread::IO, &message_loop_) {}
-
- private:
- base::MessageLoop message_loop_;
- content::TestBrowserThread ui_thread_;
- content::TestBrowserThread io_thread_;
-};
-
-// Returns a barebones test Extension object with the given name.
-static scoped_refptr<Extension> CreateExtension(const std::string& name) {
- base::FilePath path;
- PathService::Get(chrome::DIR_TEST_DATA, &path);
- path = path.AppendASCII("extensions");
-
- base::DictionaryValue manifest;
- manifest.SetString(keys::kVersion, "1.0.0.0");
- manifest.SetString(keys::kName, name);
-
- std::string error;
- scoped_refptr<Extension> extension =
- Extension::Create(path.AppendASCII(name),
- Manifest::INVALID_LOCATION,
- manifest,
- Extension::NO_FLAGS,
- &error);
- EXPECT_TRUE(extension.get()) << error;
-
- return extension;
-}
-
-static scoped_refptr<Extension> LoadManifest(const std::string& dir,
- const std::string& test_file) {
+scoped_refptr<Extension> LoadManifest(const std::string& dir,
+ const std::string& test_file) {
base::FilePath path;
PathService::Get(chrome::DIR_TEST_DATA, &path);
path = path.AppendASCII("extensions").AppendASCII(dir).AppendASCII(test_file);
@@ -76,55 +41,24 @@ static scoped_refptr<Extension> LoadManifest(const std::string& dir,
return extension;
}
-// Test that the InfoMap handles refcounting properly.
-TEST_F(InfoMapTest, RefCounting) {
- scoped_refptr<InfoMap> info_map(new InfoMap());
-
- // New extensions should have a single reference holding onto them.
- scoped_refptr<Extension> extension1(CreateExtension("extension1"));
- scoped_refptr<Extension> extension2(CreateExtension("extension2"));
- scoped_refptr<Extension> extension3(CreateExtension("extension3"));
- EXPECT_TRUE(extension1->HasOneRef());
- EXPECT_TRUE(extension2->HasOneRef());
- EXPECT_TRUE(extension3->HasOneRef());
-
- // Add a ref to each extension and give it to the info map.
- info_map->AddExtension(extension1.get(), base::Time(), false, false);
- info_map->AddExtension(extension2.get(), base::Time(), false, false);
- info_map->AddExtension(extension3.get(), base::Time(), false, false);
-
- // Release extension1, and the info map should have the only ref.
- const Extension* weak_extension1 = extension1.get();
- extension1 = NULL;
- EXPECT_TRUE(weak_extension1->HasOneRef());
-
- // Remove extension2, and the extension2 object should have the only ref.
- info_map->RemoveExtension(
- extension2->id(), extensions::UnloadedExtensionInfo::REASON_UNINSTALL);
- EXPECT_TRUE(extension2->HasOneRef());
-
- // Delete the info map, and the extension3 object should have the only ref.
- info_map = NULL;
- EXPECT_TRUE(extension3->HasOneRef());
-}
-
-// Tests that we can query a few extension properties from the InfoMap.
-TEST_F(InfoMapTest, Properties) {
- scoped_refptr<InfoMap> info_map(new InfoMap());
-
- scoped_refptr<Extension> extension1(CreateExtension("extension1"));
- scoped_refptr<Extension> extension2(CreateExtension("extension2"));
+} // namespace
- info_map->AddExtension(extension1.get(), base::Time(), false, false);
- info_map->AddExtension(extension2.get(), base::Time(), false, false);
+// This test lives in Chrome because it depends on hosted app permissions
+// (specifically, notifications) that do not exist in src/extensions.
+class ChromeInfoMapTest : public testing::Test {
+ public:
+ ChromeInfoMapTest()
+ : ui_thread_(BrowserThread::UI, &message_loop_),
+ io_thread_(BrowserThread::IO, &message_loop_) {}
- EXPECT_EQ(2u, info_map->extensions().size());
- EXPECT_EQ(extension1.get(), info_map->extensions().GetByID(extension1->id()));
- EXPECT_EQ(extension2.get(), info_map->extensions().GetByID(extension2->id()));
-}
+ private:
+ base::MessageLoop message_loop_;
+ content::TestBrowserThread ui_thread_;
+ content::TestBrowserThread io_thread_;
+};
-// Tests CheckURLAccessToExtensionPermission given both extension and app URLs.
-TEST_F(InfoMapTest, CheckPermissions) {
+// Tests API access permissions given both extension and app URLs.
+TEST_F(ChromeInfoMapTest, CheckPermissions) {
scoped_refptr<InfoMap> info_map(new InfoMap());
scoped_refptr<Extension> app(
@@ -169,10 +103,10 @@ TEST_F(InfoMapTest, CheckPermissions) {
EXPECT_FALSE(match);
}
-TEST_F(InfoMapTest, TestNotificationsDisabled) {
+TEST_F(ChromeInfoMapTest, TestNotificationsDisabled) {
scoped_refptr<InfoMap> info_map(new InfoMap());
- scoped_refptr<Extension> app(LoadManifest("manifest_tests",
- "valid_app.json"));
+ scoped_refptr<Extension> app(
+ LoadManifest("manifest_tests", "valid_app.json"));
info_map->AddExtension(app.get(), base::Time(), false, false);
EXPECT_FALSE(info_map->AreNotificationsDisabled(app->id()));
@@ -181,38 +115,4 @@ TEST_F(InfoMapTest, TestNotificationsDisabled) {
info_map->SetNotificationsDisabled(app->id(), false);
}
-// Tests that extension URLs are properly mapped to local file paths.
-TEST_F(InfoMapTest, MapUrlToLocalFilePath) {
- scoped_refptr<InfoMap> info_map(new InfoMap());
- scoped_refptr<Extension> app(CreateExtension("app"));
- info_map->AddExtension(app.get(), base::Time(), false, false);
-
- // Non-extension URLs don't map to anything.
- base::FilePath non_extension_path;
- GURL non_extension_url("http://not-an-extension.com/");
- EXPECT_FALSE(info_map->MapUrlToLocalFilePath(
- non_extension_url, false, &non_extension_path));
- EXPECT_TRUE(non_extension_path.empty());
-
- // Valid resources return a valid path.
- base::FilePath valid_path;
- GURL valid_url = app->GetResourceURL("manifest.json");
- EXPECT_TRUE(info_map->MapUrlToLocalFilePath(
- valid_url, true /* use_blocking_api */, &valid_path));
- EXPECT_FALSE(valid_path.empty());
-
- // A file must exist to be mapped to a path using the blocking API.
- base::FilePath does_not_exist_path;
- GURL does_not_exist_url = app->GetResourceURL("does-not-exist.html");
- EXPECT_FALSE(info_map->MapUrlToLocalFilePath(
- does_not_exist_url, true /* use_blocking_api */, &does_not_exist_path));
- EXPECT_TRUE(does_not_exist_path.empty());
-
- // A file does not need to exist to be mapped to a path with the non-blocking
- // API. This avoids hitting the disk to see if it exists.
- EXPECT_TRUE(info_map->MapUrlToLocalFilePath(
- does_not_exist_url, false /* use_blocking_api */, &does_not_exist_path));
- EXPECT_FALSE(does_not_exist_path.empty());
-}
-
} // namespace extensions
« no previous file with comments | « no previous file | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698