| Index: chrome/browser/extensions/user_script_loader_unittest.cc
|
| diff --git a/chrome/browser/extensions/user_script_master_unittest.cc b/chrome/browser/extensions/user_script_loader_unittest.cc
|
| similarity index 79%
|
| rename from chrome/browser/extensions/user_script_master_unittest.cc
|
| rename to chrome/browser/extensions/user_script_loader_unittest.cc
|
| index 4731ceb851cb922deeeb504ac141f818bed0e282..f604c18b240e9a08015ef076d2b1a8132a2949ab 100644
|
| --- a/chrome/browser/extensions/user_script_master_unittest.cc
|
| +++ b/chrome/browser/extensions/user_script_loader_unittest.cc
|
| @@ -2,8 +2,9 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "chrome/browser/extensions/user_script_master.h"
|
| +#include "chrome/browser/extensions/user_script_loader.h"
|
|
|
| +#include <set>
|
| #include <string>
|
|
|
| #include "base/file_util.h"
|
| @@ -14,6 +15,7 @@
|
| #include "base/strings/string_util.h"
|
| #include "chrome/browser/chrome_notification_types.h"
|
| #include "chrome/test/base/testing_profile.h"
|
| +#include "content/public/browser/notification_observer.h"
|
| #include "content/public/browser/notification_registrar.h"
|
| #include "content/public/browser/notification_service.h"
|
| #include "content/public/test/test_browser_thread.h"
|
| @@ -28,19 +30,17 @@ static void AddPattern(URLPatternSet* extent, const std::string& pattern) {
|
| int schemes = URLPattern::SCHEME_ALL;
|
| extent->AddPattern(URLPattern(schemes, pattern));
|
| }
|
| -
|
| }
|
|
|
| namespace extensions {
|
|
|
| -// Test bringing up a master on a specific directory, putting a script
|
| +// Test bringing up a script loader on a specific directory, putting a script
|
| // in there, etc.
|
|
|
| -class UserScriptMasterTest : public testing::Test,
|
| +class UserScriptLoaderTest : public testing::Test,
|
| public content::NotificationObserver {
|
| public:
|
| - UserScriptMasterTest() : shared_memory_(NULL) {
|
| - }
|
| + UserScriptLoaderTest() : shared_memory_(NULL) {}
|
|
|
| virtual void SetUp() {
|
| ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
|
| @@ -50,7 +50,7 @@ class UserScriptMasterTest : public testing::Test,
|
| extensions::NOTIFICATION_USER_SCRIPTS_UPDATED,
|
| content::NotificationService::AllSources());
|
|
|
| - // UserScriptMaster posts tasks to the file thread so make the current
|
| + // UserScriptLoader posts tasks to the file thread so make the current
|
| // thread look like one.
|
| file_thread_.reset(new content::TestBrowserThread(
|
| BrowserThread::FILE, base::MessageLoop::current()));
|
| @@ -89,17 +89,19 @@ class UserScriptMasterTest : public testing::Test,
|
| };
|
|
|
| // Test that we get notified even when there are no scripts.
|
| -TEST_F(UserScriptMasterTest, NoScripts) {
|
| +TEST_F(UserScriptLoaderTest, NoScripts) {
|
| TestingProfile profile;
|
| - UserScriptMaster master(&profile);
|
| - master.StartLoad();
|
| + UserScriptLoader loader(&profile,
|
| + std::string() /* owner_extension_id */,
|
| + true /* listen_for_extension_system_loaded */);
|
| + loader.StartLoad();
|
| message_loop_.PostTask(FROM_HERE, base::MessageLoop::QuitClosure());
|
| message_loop_.Run();
|
|
|
| ASSERT_TRUE(shared_memory_ != NULL);
|
| }
|
|
|
| -TEST_F(UserScriptMasterTest, Parse1) {
|
| +TEST_F(UserScriptLoaderTest, Parse1) {
|
| const std::string text(
|
| "// This is my awesome script\n"
|
| "// It does stuff.\n"
|
| @@ -118,35 +120,35 @@ TEST_F(UserScriptMasterTest, Parse1) {
|
| "alert('hoo!');\n");
|
|
|
| UserScript script;
|
| - EXPECT_TRUE(UserScriptMaster::ParseMetadataHeader(text, &script));
|
| + EXPECT_TRUE(UserScriptLoader::ParseMetadataHeader(text, &script));
|
| ASSERT_EQ(3U, script.globs().size());
|
| EXPECT_EQ("*mail.google.com*", script.globs()[0]);
|
| EXPECT_EQ("*mail.yahoo.com*", script.globs()[1]);
|
| EXPECT_EQ("*mail.msn.com*", script.globs()[2]);
|
| }
|
|
|
| -TEST_F(UserScriptMasterTest, Parse2) {
|
| +TEST_F(UserScriptLoaderTest, Parse2) {
|
| const std::string text("default to @include *");
|
|
|
| UserScript script;
|
| - EXPECT_TRUE(UserScriptMaster::ParseMetadataHeader(text, &script));
|
| + EXPECT_TRUE(UserScriptLoader::ParseMetadataHeader(text, &script));
|
| ASSERT_EQ(1U, script.globs().size());
|
| EXPECT_EQ("*", script.globs()[0]);
|
| }
|
|
|
| -TEST_F(UserScriptMasterTest, Parse3) {
|
| +TEST_F(UserScriptLoaderTest, Parse3) {
|
| const std::string text(
|
| "// ==UserScript==\n"
|
| "// @include *foo*\n"
|
| "// ==/UserScript=="); // no trailing newline
|
|
|
| UserScript script;
|
| - UserScriptMaster::ParseMetadataHeader(text, &script);
|
| + UserScriptLoader::ParseMetadataHeader(text, &script);
|
| ASSERT_EQ(1U, script.globs().size());
|
| EXPECT_EQ("*foo*", script.globs()[0]);
|
| }
|
|
|
| -TEST_F(UserScriptMasterTest, Parse4) {
|
| +TEST_F(UserScriptLoaderTest, Parse4) {
|
| const std::string text(
|
| "// ==UserScript==\n"
|
| "// @match http://*.mail.google.com/*\n"
|
| @@ -158,12 +160,12 @@ TEST_F(UserScriptMasterTest, Parse4) {
|
| AddPattern(&expected_patterns, "http://mail.yahoo.com/*");
|
|
|
| UserScript script;
|
| - EXPECT_TRUE(UserScriptMaster::ParseMetadataHeader(text, &script));
|
| + EXPECT_TRUE(UserScriptLoader::ParseMetadataHeader(text, &script));
|
| EXPECT_EQ(0U, script.globs().size());
|
| EXPECT_EQ(expected_patterns, script.url_patterns());
|
| }
|
|
|
| -TEST_F(UserScriptMasterTest, Parse5) {
|
| +TEST_F(UserScriptLoaderTest, Parse5) {
|
| const std::string text(
|
| "// ==UserScript==\n"
|
| "// @match http://*mail.google.com/*\n"
|
| @@ -171,10 +173,10 @@ TEST_F(UserScriptMasterTest, Parse5) {
|
|
|
| // Invalid @match value.
|
| UserScript script;
|
| - EXPECT_FALSE(UserScriptMaster::ParseMetadataHeader(text, &script));
|
| + EXPECT_FALSE(UserScriptLoader::ParseMetadataHeader(text, &script));
|
| }
|
|
|
| -TEST_F(UserScriptMasterTest, Parse6) {
|
| +TEST_F(UserScriptLoaderTest, Parse6) {
|
| const std::string text(
|
| "// ==UserScript==\n"
|
| "// @include http://*.mail.google.com/*\n"
|
| @@ -183,10 +185,10 @@ TEST_F(UserScriptMasterTest, Parse6) {
|
|
|
| // Allowed to match @include and @match.
|
| UserScript script;
|
| - EXPECT_TRUE(UserScriptMaster::ParseMetadataHeader(text, &script));
|
| + EXPECT_TRUE(UserScriptLoader::ParseMetadataHeader(text, &script));
|
| }
|
|
|
| -TEST_F(UserScriptMasterTest, Parse7) {
|
| +TEST_F(UserScriptLoaderTest, Parse7) {
|
| // Greasemonkey allows there to be any leading text before the comment marker.
|
| const std::string text(
|
| "// ==UserScript==\n"
|
| @@ -196,7 +198,7 @@ TEST_F(UserScriptMasterTest, Parse7) {
|
| "// ==/UserScript==\n");
|
|
|
| UserScript script;
|
| - EXPECT_TRUE(UserScriptMaster::ParseMetadataHeader(text, &script));
|
| + EXPECT_TRUE(UserScriptLoader::ParseMetadataHeader(text, &script));
|
| ASSERT_EQ("hello", script.name());
|
| ASSERT_EQ("wiggity woo", script.description());
|
| ASSERT_EQ(1U, script.url_patterns().patterns().size());
|
| @@ -204,7 +206,7 @@ TEST_F(UserScriptMasterTest, Parse7) {
|
| script.url_patterns().begin()->GetAsString());
|
| }
|
|
|
| -TEST_F(UserScriptMasterTest, Parse8) {
|
| +TEST_F(UserScriptLoaderTest, Parse8) {
|
| const std::string text(
|
| "// ==UserScript==\n"
|
| "// @name myscript\n"
|
| @@ -213,7 +215,7 @@ TEST_F(UserScriptMasterTest, Parse8) {
|
| "// ==/UserScript==\n");
|
|
|
| UserScript script;
|
| - EXPECT_TRUE(UserScriptMaster::ParseMetadataHeader(text, &script));
|
| + EXPECT_TRUE(UserScriptLoader::ParseMetadataHeader(text, &script));
|
| ASSERT_EQ("myscript", script.name());
|
| ASSERT_EQ(1U, script.url_patterns().patterns().size());
|
| EXPECT_EQ("http://www.google.com/*",
|
| @@ -223,26 +225,26 @@ TEST_F(UserScriptMasterTest, Parse8) {
|
| script.exclude_url_patterns().begin()->GetAsString());
|
| }
|
|
|
| -TEST_F(UserScriptMasterTest, SkipBOMAtTheBeginning) {
|
| +TEST_F(UserScriptLoaderTest, SkipBOMAtTheBeginning) {
|
| base::FilePath path = temp_dir_.path().AppendASCII("script.user.js");
|
| const std::string content("\xEF\xBB\xBF alert('hello');");
|
| size_t written = base::WriteFile(path, content.c_str(), content.size());
|
| ASSERT_EQ(written, content.size());
|
|
|
| UserScript user_script;
|
| - user_script.js_scripts().push_back(UserScript::File(
|
| - temp_dir_.path(), path.BaseName(), GURL()));
|
| + user_script.js_scripts().push_back(
|
| + UserScript::File(temp_dir_.path(), path.BaseName(), GURL()));
|
|
|
| UserScriptList user_scripts;
|
| user_scripts.push_back(user_script);
|
|
|
| - UserScriptMaster::LoadScriptsForTest(&user_scripts);
|
| + UserScriptLoader::LoadScriptsForTest(&user_scripts);
|
|
|
| EXPECT_EQ(content.substr(3),
|
| user_scripts[0].js_scripts()[0].GetContent().as_string());
|
| }
|
|
|
| -TEST_F(UserScriptMasterTest, LeaveBOMNotAtTheBeginning) {
|
| +TEST_F(UserScriptLoaderTest, LeaveBOMNotAtTheBeginning) {
|
| base::FilePath path = temp_dir_.path().AppendASCII("script.user.js");
|
| const std::string content("alert('here's a BOOM: \xEF\xBB\xBF');");
|
| size_t written = base::WriteFile(path, content.c_str(), content.size());
|
| @@ -255,7 +257,7 @@ TEST_F(UserScriptMasterTest, LeaveBOMNotAtTheBeginning) {
|
| UserScriptList user_scripts;
|
| user_scripts.push_back(user_script);
|
|
|
| - UserScriptMaster::LoadScriptsForTest(&user_scripts);
|
| + UserScriptLoader::LoadScriptsForTest(&user_scripts);
|
|
|
| EXPECT_EQ(content, user_scripts[0].js_scripts()[0].GetContent().as_string());
|
| }
|
|
|