diff options
author | yoz@chromium.org <yoz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-05 13:55:23 +0000 |
---|---|---|
committer | yoz@chromium.org <yoz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-05 13:55:23 +0000 |
commit | e087d17d2b2ec5137420280b7bac56545f1fb823 (patch) | |
tree | c9681616888840aaf6799ccd5ea6835e9627cb6e | |
parent | d346a27b6478db16bf8917987f4b369193303703 (diff) | |
download | chromium_src-e087d17d2b2ec5137420280b7bac56545f1fb823.zip chromium_src-e087d17d2b2ec5137420280b7bac56545f1fb823.tar.gz chromium_src-e087d17d2b2ec5137420280b7bac56545f1fb823.tar.bz2 |
Dispatch browser action clicks to the profile for the browser window.
This fixes a bug where incognito split mode extensions were getting clicks from incognito browsers sent to the regular profile.
BUG=314142
Review URL: https://codereview.chromium.org/50433008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@232968 0039d316-1c4b-4281-b951-d872f2087c98
4 files changed, 65 insertions, 1 deletions
diff --git a/chrome/browser/extensions/api/extension_action/browser_action_apitest.cc b/chrome/browser/extensions/api/extension_action/browser_action_apitest.cc index dc680e3..81ebc79 100644 --- a/chrome/browser/extensions/api/extension_action/browser_action_apitest.cc +++ b/chrome/browser/extensions/api/extension_action/browser_action_apitest.cc @@ -571,6 +571,39 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, IncognitoDragging) { EXPECT_EQ(kTooltipA, incognito_bar.GetTooltip(1)); } +// Tests that events are dispatched to the correct profile for split mode +// extensions. +IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, IncognitoSplit) { + ResultCatcher catcher; + const Extension* extension = LoadExtensionWithFlags( + test_data_dir_.AppendASCII("browser_action/split_mode"), + kFlagEnableIncognito); + ASSERT_TRUE(extension) << message_; + + // Open an incognito window. + Profile* incognito_profile = browser()->profile()->GetOffTheRecordProfile(); + Browser* incognito_browser = + new Browser(Browser::CreateParams(incognito_profile, + browser()->host_desktop_type())); + // Navigate just to have a tab in this window, otherwise wonky things happen. + ui_test_utils::OpenURLOffTheRecord(browser()->profile(), GURL("about:blank")); + ASSERT_EQ(1, + BrowserActionTestUtil(incognito_browser).NumberOfBrowserActions()); + + // A click in the regular profile should open a tab in the regular profile. + ExtensionService* service = extensions::ExtensionSystem::Get( + browser()->profile())->extension_service(); + service->toolbar_model()->ExecuteBrowserAction( + extension, browser(), NULL, true); + ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); + + // A click in the incognito profile should open a tab in the + // incognito profile. + service->toolbar_model()->ExecuteBrowserAction( + extension, incognito_browser, NULL, true); + ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); +} + // Disabled because of failures (crashes) on ASAN bot. // See http://crbug.com/98861. IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, DISABLED_CloseBackgroundPage) { diff --git a/chrome/browser/extensions/extension_toolbar_model.cc b/chrome/browser/extensions/extension_toolbar_model.cc index a3a61e6..34049e0 100644 --- a/chrome/browser/extensions/extension_toolbar_model.cc +++ b/chrome/browser/extensions/extension_toolbar_model.cc @@ -163,7 +163,7 @@ ExtensionToolbarModel::Action ExtensionToolbarModel::ExecuteBrowserAction( } extensions::ExtensionActionAPI::BrowserActionExecuted( - service_->profile(), *browser_action, web_contents); + browser->profile(), *browser_action, web_contents); return ACTION_NONE; } diff --git a/chrome/test/data/extensions/api_test/browser_action/split_mode/background.js b/chrome/test/data/extensions/api_test/browser_action/split_mode/background.js new file mode 100644 index 0000000..9075100 --- /dev/null +++ b/chrome/test/data/extensions/api_test/browser_action/split_mode/background.js @@ -0,0 +1,17 @@ +// Copyright 2013 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. + +chrome.browserAction.onClicked.addListener(function(tab) { + chrome.tabs.create({ url: 'about:blank' }, function(newtab) { + chrome.windows.get(tab.windowId, { populate: true }, function(window) { + if (!window) { + chrome.test.notifyFail( + 'Could not get window for the tab (probably due to wrong profile)'); + return; + } + chrome.test.assertEq(2, window.tabs.length); + chrome.test.notifyPass(); + }); + }); +}); diff --git a/chrome/test/data/extensions/api_test/browser_action/split_mode/manifest.json b/chrome/test/data/extensions/api_test/browser_action/split_mode/manifest.json new file mode 100644 index 0000000..97dd873 --- /dev/null +++ b/chrome/test/data/extensions/api_test/browser_action/split_mode/manifest.json @@ -0,0 +1,14 @@ +{ + "name": "Split mode browser action test", + "description": "", + "version": "0", + "manifest_version": 2, + "browser_action": { + "default_title": "create a tab" + }, + "background": { + "scripts": ["background.js"], + "persistent": false + }, + "incognito": "split" +} |