diff options
author | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-24 22:28:14 +0000 |
---|---|---|
committer | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-24 22:28:14 +0000 |
commit | a6e82fccc2b73736c7a99e6293c6dfc04c6957ae (patch) | |
tree | bfd0f3eadbc4fd2e7c9212f6a432b6a947cced2c /chrome | |
parent | 8ceb44c74fc375df749b60acc6fc01b5327c6d18 (diff) | |
download | chromium_src-a6e82fccc2b73736c7a99e6293c6dfc04c6957ae.zip chromium_src-a6e82fccc2b73736c7a99e6293c6dfc04c6957ae.tar.gz chromium_src-a6e82fccc2b73736c7a99e6293c6dfc04c6957ae.tar.bz2 |
Make sure in-page navigations don't make the page actions disappear.
Also added unit test to catch future regressions.
BUG=35935
TEST=ExtensionBrowserTest.PageActionInPageNavigation
Review URL: http://codereview.chromium.org/660012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@39938 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
8 files changed, 117 insertions, 6 deletions
diff --git a/chrome/browser/extensions/extension_browsertests_misc.cc b/chrome/browser/extensions/extension_browsertests_misc.cc index ddc9b6f..9f8a440 100644 --- a/chrome/browser/extensions/extension_browsertests_misc.cc +++ b/chrome/browser/extensions/extension_browsertests_misc.cc @@ -43,8 +43,12 @@ const std::wstring kValidFeedNoLinks = L"files/feeds/feed_nolinks.xml"; const std::wstring kInvalidFeed1 = L"files/feeds/feed_invalid1.xml"; const std::wstring kInvalidFeed2 = L"files/feeds/feed_invalid2.xml"; const std::wstring kLocalization = - L"file/extensions/browsertest/title_localized_pa/simple.html"; -const std::wstring kTestFile = L"file/extensions/test_file.html"; + L"files/extensions/browsertest/title_localized_pa/simple.html"; +const std::wstring kHashPageA = + L"files/extensions/api_test/page_action/hash_change/test_page_A.html"; +const std::wstring kHashPageAHash = kHashPageA + L"#asdf"; +const std::wstring kHashPageB = + L"files/extensions/api_test/page_action/hash_change/test_page_B.html"; // Looks for an ExtensionHost whose URL has the given path component (including // leading slash). Also verifies that the expected number of hosts are loaded. @@ -228,6 +232,31 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, PageAction) { ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(0)); } +// Tests that we don't lose the page action icon on in-page navigations. +IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, PageActionInPageNavigation) { + HTTPTestServer* server = StartHTTPServer(); + + FilePath extension_path(test_data_dir_.AppendASCII("api_test") + .AppendASCII("page_action") + .AppendASCII("hash_change")); + ASSERT_TRUE(LoadExtension(extension_path)); + + // Page action should become visible when we navigate here. + GURL feed_url = server->TestServerPageW(kHashPageA); + ui_test_utils::NavigateToURL(browser(), feed_url); + ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1)); + + // In-page navigation, page action should remain. + feed_url = server->TestServerPageW(kHashPageAHash); + ui_test_utils::NavigateToURL(browser(), feed_url); + ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1)); + + // Not an in-page navigation, page action should go away. + feed_url = server->TestServerPageW(kHashPageB); + ui_test_utils::NavigateToURL(browser(), feed_url); + ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(0)); +} + // Tests that the location bar forgets about unloaded page actions. IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, UnloadPageAction) { HTTPTestServer* server = StartHTTPServer(); diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc index 98f463b..c3f70d6 100644 --- a/chrome/browser/tab_contents/tab_contents.cc +++ b/chrome/browser/tab_contents/tab_contents.cc @@ -1458,10 +1458,7 @@ void TabContents::DidNavigateMainFramePostCommit( // Clear all page actions, blocked content notifications and browser actions // for this tab, unless this is an in-page navigation. - url_canon::Replacements<char> replacements; - replacements.ClearRef(); - if (params.url.ReplaceComponents(replacements) != - params.referrer.ReplaceComponents(replacements)) { + if (!details.is_in_page) { ExtensionsService* service = profile()->GetExtensionsService(); if (service) { for (size_t i = 0; i < service->extensions()->size(); ++i) { diff --git a/chrome/test/data/extensions/api_test/page_action/hash_change/background.html b/chrome/test/data/extensions/api_test/page_action/hash_change/background.html new file mode 100644 index 0000000..5340407 --- /dev/null +++ b/chrome/test/data/extensions/api_test/page_action/hash_change/background.html @@ -0,0 +1,35 @@ +<!-- + * Copyright (c) 2010 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. +--> +<html> +<head> +<script> + // This makes sure we only enable the page action once per tab. + var hasEnabled = {}; + + chrome.extension.onRequest.addListener(function(request, sender) { + if (request.msg == "feedIcon") { + console.log('url: ' + sender.tab.url); + + if (!hasEnabled[sender.tab.id]) { + console.log('Enabling for ' + sender.tab.id); + + // We have received a list of feed urls found on the page. + // Enable the page action icon. + chrome.pageAction.setTitle({ tabId: sender.tab.id, + title: "Page action..."}); + chrome.pageAction.show(sender.tab.id); + hasEnabled[sender.tab.id] = true; + hasEnabledLastTabId = sender.tab.id; + } else {
+ console.log('We are not doing this more than once (for ' + + sender.tab.id + ')'); + } + } + }); + +</script> +</head> +</html> diff --git a/chrome/test/data/extensions/api_test/page_action/hash_change/icon.png b/chrome/test/data/extensions/api_test/page_action/hash_change/icon.png Binary files differnew file mode 100644 index 0000000..9a79a46 --- /dev/null +++ b/chrome/test/data/extensions/api_test/page_action/hash_change/icon.png diff --git a/chrome/test/data/extensions/api_test/page_action/hash_change/manifest.json b/chrome/test/data/extensions/api_test/page_action/hash_change/manifest.json new file mode 100644 index 0000000..489e3bc --- /dev/null +++ b/chrome/test/data/extensions/api_test/page_action/hash_change/manifest.json @@ -0,0 +1,15 @@ +{ + "background_page": "background.html", + "content_scripts": [ { + "js": [ "script.js" ], + "matches": [ "http://*/*", "https://*/*" ] + } ], + "description": "Test url changes with hash-code", + "name": "Hash-code changes", + "page_action": { + "default_icon": "icon.png", + "default_title": "Page action" + }, + "permissions": [ "tabs", "http://*/*", "https://*/*" ], + "version": "1.0" +} diff --git a/chrome/test/data/extensions/api_test/page_action/hash_change/script.js b/chrome/test/data/extensions/api_test/page_action/hash_change/script.js new file mode 100644 index 0000000..745c55d --- /dev/null +++ b/chrome/test/data/extensions/api_test/page_action/hash_change/script.js @@ -0,0 +1,7 @@ +// Copyright (c) 2010 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. + + +// Notify the extension needs to show the page action icon. +chrome.extension.sendRequest({msg: "feedIcon"}); diff --git a/chrome/test/data/extensions/api_test/page_action/hash_change/test_page_A.html b/chrome/test/data/extensions/api_test/page_action/hash_change/test_page_A.html new file mode 100644 index 0000000..663af06 --- /dev/null +++ b/chrome/test/data/extensions/api_test/page_action/hash_change/test_page_A.html @@ -0,0 +1,14 @@ +<!-- + * Copyright (c) 2010 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. +--> +<html> +<a href="#fragmentA">Click me to add a fragment</a> +<br> +<br> +<a href="#fragmentB">and another</a> +<br> +<br> +<a href="#fragmentC">and yet another</a> +</html>
\ No newline at end of file diff --git a/chrome/test/data/extensions/api_test/page_action/hash_change/test_page_B.html b/chrome/test/data/extensions/api_test/page_action/hash_change/test_page_B.html new file mode 100644 index 0000000..663af06 --- /dev/null +++ b/chrome/test/data/extensions/api_test/page_action/hash_change/test_page_B.html @@ -0,0 +1,14 @@ +<!-- + * Copyright (c) 2010 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. +--> +<html> +<a href="#fragmentA">Click me to add a fragment</a> +<br> +<br> +<a href="#fragmentB">and another</a> +<br> +<br> +<a href="#fragmentC">and yet another</a> +</html>
\ No newline at end of file |