This source file includes following definitions.
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
#include "base/command_line.h"
#include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_test_message_listener.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/test/base/test_switches.h"
#include "chrome/test/base/ui_test_utils.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/extension.h"
#include "extensions/common/extensions_client.h"
#include "extensions/common/id_util.h"
const std::string kAllUrlsTarget =
"files/extensions/api_test/all_urls/index.html";
typedef ExtensionApiTest AllUrlsApiTest;
#if defined(OS_WIN) && !defined(NDEBUG)
#define MAYBE_WhitelistedExtension DISABLED_WhitelistedExtension
#else
#define MAYBE_WhitelistedExtension WhitelistedExtension
#endif
IN_PROC_BROWSER_TEST_F(AllUrlsApiTest, MAYBE_WhitelistedExtension) {
#if defined(OS_WIN) && defined(USE_ASH)
if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests))
return;
#endif
base::FilePath extension_dir1 = test_data_dir_.AppendASCII("all_urls")
.AppendASCII("content_script");
base::FilePath extension_dir2 = test_data_dir_.AppendASCII("all_urls")
.AppendASCII("execute_script");
extensions::ExtensionsClient::ScriptingWhitelist whitelist;
whitelist.push_back(extensions::id_util::GenerateIdForPath(extension_dir1));
whitelist.push_back(extensions::id_util::GenerateIdForPath(extension_dir2));
extensions::ExtensionsClient::Get()->SetScriptingWhitelist(whitelist);
ExtensionService* service = extensions::ExtensionSystem::Get(
browser()->profile())->extension_service();
const size_t size_before = service->extensions()->size();
ASSERT_TRUE(LoadExtension(extension_dir1));
ASSERT_TRUE(LoadExtension(extension_dir2));
EXPECT_EQ(size_before + 2, service->extensions()->size());
std::string url;
url = "chrome://newtab/";
ExtensionTestMessageListener listener1a("content script: " + url, false);
ExtensionTestMessageListener listener1b("execute: " + url, false);
ui_test_utils::NavigateToURL(browser(), GURL(url));
ASSERT_TRUE(listener1a.WaitUntilSatisfied());
ASSERT_TRUE(listener1b.WaitUntilSatisfied());
url = "data:text/html;charset=utf-8,<html>asdf</html>";
ExtensionTestMessageListener listener2a("content script: " + url, false);
ExtensionTestMessageListener listener2b("execute: " + url, false);
ui_test_utils::NavigateToURL(browser(), GURL(url));
ASSERT_TRUE(listener2a.WaitUntilSatisfied());
ASSERT_TRUE(listener2b.WaitUntilSatisfied());
url = "chrome://version/";
ExtensionTestMessageListener listener3a("content script: " + url, false);
ExtensionTestMessageListener listener3b("execute: " + url, false);
ui_test_utils::NavigateToURL(browser(), GURL(url));
ASSERT_TRUE(listener3a.WaitUntilSatisfied());
ASSERT_TRUE(listener3b.WaitUntilSatisfied());
url = "about:blank";
ExtensionTestMessageListener listener4a("content script: " + url, false);
ExtensionTestMessageListener listener4b("execute: " + url, false);
ui_test_utils::NavigateToURL(browser(), GURL(url));
ASSERT_TRUE(listener4a.WaitUntilSatisfied());
ASSERT_TRUE(listener4b.WaitUntilSatisfied());
ASSERT_TRUE(test_server()->Start());
GURL page_url = test_server()->GetURL(kAllUrlsTarget);
ExtensionTestMessageListener listener5a("content script: " + page_url.spec(),
false);
ExtensionTestMessageListener listener5b("execute: " + page_url.spec(), false);
ui_test_utils::NavigateToURL(browser(), page_url);
ASSERT_TRUE(listener5a.WaitUntilSatisfied());
ASSERT_TRUE(listener5b.WaitUntilSatisfied());
}
IN_PROC_BROWSER_TEST_F(AllUrlsApiTest, RegularExtensions) {
base::FilePath extension_dir1 = test_data_dir_.AppendASCII("all_urls")
.AppendASCII("content_script");
base::FilePath extension_dir2 = test_data_dir_.AppendASCII("all_urls")
.AppendASCII("execute_script");
ExtensionService* service = extensions::ExtensionSystem::Get(
browser()->profile())->extension_service();
const size_t size_before = service->extensions()->size();
ASSERT_TRUE(LoadExtension(extension_dir1));
ASSERT_TRUE(LoadExtension(extension_dir2));
EXPECT_EQ(size_before + 2, service->extensions()->size());
ASSERT_TRUE(test_server()->Start());
GURL page_url = test_server()->GetURL(kAllUrlsTarget);
ExtensionTestMessageListener listener1a("content script: " + page_url.spec(),
false);
ExtensionTestMessageListener listener1b("execute: " + page_url.spec(), false);
ui_test_utils::NavigateToURL(browser(), page_url);
ASSERT_TRUE(listener1a.WaitUntilSatisfied());
ASSERT_TRUE(listener1b.WaitUntilSatisfied());
}