This source file includes following definitions.
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/extensions/extension_action.h"
#include "chrome/browser/extensions/extension_action_manager.h"
#include "chrome/browser/extensions/extension_browsertest.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_tab_util.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/test/base/ui_test_utils.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/extension.h"
#include "extensions/common/switches.h"
namespace extensions {
namespace {
const std::string kFeedPage = "files/feeds/feed.html";
const std::string kNoFeedPage = "files/feeds/no_feed.html";
const std::string kLocalization =
"files/extensions/browsertest/title_localized_pa/simple.html";
const std::string kHashPageA =
"files/extensions/api_test/page_action/hash_change/test_page_A.html";
const std::string kHashPageAHash = kHashPageA + "#asdf";
const std::string kHashPageB =
"files/extensions/api_test/page_action/hash_change/test_page_B.html";
IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, PageActionCrash25562) {
ASSERT_TRUE(test_server()->Start());
CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kAllowLegacyExtensionManifests);
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("browsertest")
.AppendASCII("crash_25562")));
GURL feed_url = test_server()->GetURL(kFeedPage);
ui_test_utils::NavigateToURL(browser(), feed_url);
ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1));
}
IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, PageAction) {
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("subscribe_page_action")));
ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(0));
GURL feed_url = test_server()->GetURL(kFeedPage);
ui_test_utils::NavigateToURL(browser(), feed_url);
ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1));
GURL no_feed = test_server()->GetURL(kNoFeedPage);
ui_test_utils::NavigateToURL(browser(), no_feed);
ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(0));
}
IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, PageActionInPageNavigation) {
ASSERT_TRUE(test_server()->Start());
base::FilePath extension_path(test_data_dir_.AppendASCII("api_test")
.AppendASCII("page_action")
.AppendASCII("hash_change"));
ASSERT_TRUE(LoadExtension(extension_path));
GURL feed_url = test_server()->GetURL(kHashPageA);
ui_test_utils::NavigateToURL(browser(), feed_url);
ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1));
feed_url = test_server()->GetURL(kHashPageAHash);
ui_test_utils::NavigateToURL(browser(), feed_url);
ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1));
feed_url = test_server()->GetURL(kHashPageB);
ui_test_utils::NavigateToURL(browser(), feed_url);
ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(0));
}
IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, UnloadPageAction) {
ASSERT_TRUE(test_server()->Start());
base::FilePath extension_path(
test_data_dir_.AppendASCII("subscribe_page_action"));
ASSERT_TRUE(LoadExtension(extension_path));
GURL feed_url = test_server()->GetURL(kFeedPage);
ui_test_utils::NavigateToURL(browser(), feed_url);
ASSERT_TRUE(WaitForPageActionCountChangeTo(1));
UnloadExtension(last_loaded_extension_id());
ASSERT_TRUE(WaitForPageActionCountChangeTo(0));
}
IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, PageActionRefreshCrash) {
base::TimeTicks start_time = base::TimeTicks::Now();
ExtensionService* service = extensions::ExtensionSystem::Get(
browser()->profile())->extension_service();
size_t size_before = service->extensions()->size();
base::FilePath base_path = test_data_dir_.AppendASCII("browsertest")
.AppendASCII("crash_44415");
const Extension* extensionA = LoadExtension(base_path.AppendASCII("ExtA"));
ASSERT_TRUE(extensionA);
ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1));
ASSERT_EQ(size_before + 1, service->extensions()->size());
LOG(INFO) << "Load extension A done : "
<< (base::TimeTicks::Now() - start_time).InMilliseconds()
<< " ms" << std::flush;
const Extension* extensionB = LoadExtension(base_path.AppendASCII("ExtB"));
ASSERT_TRUE(extensionB);
ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(2));
ASSERT_EQ(size_before + 2, service->extensions()->size());
LOG(INFO) << "Load extension B done : "
<< (base::TimeTicks::Now() - start_time).InMilliseconds()
<< " ms" << std::flush;
std::string idA = extensionA->id();
ReloadExtension(extensionA->id());
ASSERT_EQ(size_before + 2, service->extensions()->size());
extensionA = service->extensions()->GetByID(idA);
LOG(INFO) << "Reload extension A done: "
<< (base::TimeTicks::Now() - start_time).InMilliseconds()
<< " ms" << std::flush;
ReloadExtension(extensionB->id());
LOG(INFO) << "Reload extension B done: "
<< (base::TimeTicks::Now() - start_time).InMilliseconds()
<< " ms" << std::flush;
ReloadExtension(extensionA->id());
LOG(INFO) << "Test completed : "
<< (base::TimeTicks::Now() - start_time).InMilliseconds()
<< " ms" << std::flush;
}
IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, TitleLocalizationPageAction) {
ASSERT_TRUE(test_server()->Start());
ExtensionService* service = extensions::ExtensionSystem::Get(
browser()->profile())->extension_service();
const size_t size_before = service->extensions()->size();
base::FilePath extension_path(test_data_dir_.AppendASCII("browsertest")
.AppendASCII("title_localized_pa"));
const Extension* extension = LoadExtension(extension_path);
ASSERT_TRUE(extension);
GURL url = test_server()->GetURL(kLocalization);
ui_test_utils::NavigateToURL(browser(), url);
ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1));
ASSERT_EQ(size_before + 1, service->extensions()->size());
EXPECT_STREQ(base::WideToUTF8(L"Hreggvi\u00F0ur: l10n page action").c_str(),
extension->description().c_str());
EXPECT_STREQ(base::WideToUTF8(L"Hreggvi\u00F0ur is my name").c_str(),
extension->name().c_str());
int tab_id = ExtensionTabUtil::GetTabId(
browser()->tab_strip_model()->GetActiveWebContents());
EXPECT_STREQ(base::WideToUTF8(L"Hreggvi\u00F0ur").c_str(),
ExtensionActionManager::Get(browser()->profile())->
GetPageAction(*extension)->
GetTitle(tab_id).c_str());
}
}
}