summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/extension_context_menu_browsertest.cc
diff options
context:
space:
mode:
authormpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-02 20:52:19 +0000
committermpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-02 20:52:19 +0000
commit5a7b5eaf2d0c6036a6e13767050d5fb9e6d771ef (patch)
treedb5a8a5de93829cbe3add9cd3eeb1985e547161c /chrome/browser/extensions/extension_context_menu_browsertest.cc
parentde970f348af1438c28c85c84d185be9d89e42680 (diff)
downloadchromium_src-5a7b5eaf2d0c6036a6e13767050d5fb9e6d771ef.zip
chromium_src-5a7b5eaf2d0c6036a6e13767050d5fb9e6d771ef.tar.gz
chromium_src-5a7b5eaf2d0c6036a6e13767050d5fb9e6d771ef.tar.bz2
Fix bug with context menus in incognito mode.
If an extension uses "spanning" mode, the context menu items are shared between profiles. If an extension uses "split" mode, the items are separate per profile. In either case, they only appear in incognito if the extension is enabled in incognito. Also fixed a minor bug, so that tabs.create now can open extension URLs in incognito if the extension uses split mode. BUG=61147 TEST=see bug for repro steps; context menu items should work in incognito mode Review URL: http://codereview.chromium.org/4090011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@64812 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extension_context_menu_browsertest.cc')
-rw-r--r--chrome/browser/extensions/extension_context_menu_browsertest.cc73
1 files changed, 66 insertions, 7 deletions
diff --git a/chrome/browser/extensions/extension_context_menu_browsertest.cc b/chrome/browser/extensions/extension_context_menu_browsertest.cc
index b0041ad..73f4acf 100644
--- a/chrome/browser/extensions/extension_context_menu_browsertest.cc
+++ b/chrome/browser/extensions/extension_context_menu_browsertest.cc
@@ -5,6 +5,7 @@
#include "app/menus/menu_model.h"
#include "chrome/app/chrome_dll_resource.h"
#include "chrome/browser/browser.h"
+#include "chrome/browser/browser_list.h"
#include "chrome/browser/extensions/extension_browsertest.h"
#include "chrome/browser/extensions/extension_test_message_listener.h"
#include "chrome/browser/extensions/extensions_service.h"
@@ -122,9 +123,16 @@ class ExtensionContextMenuBrowserTest : public ExtensionBrowserTest {
return LoadExtension(extension_dir);
}
- TestRenderViewContextMenu* CreateMenu(const GURL& page_url,
+ bool LoadContextMenuExtensionIncognito(std::string subdirectory) {
+ FilePath extension_dir =
+ test_data_dir_.AppendASCII("context_menus").AppendASCII(subdirectory);
+ return LoadExtensionIncognito(extension_dir);
+ }
+
+ TestRenderViewContextMenu* CreateMenu(Browser* browser,
+ const GURL& page_url,
const GURL& link_url) {
- TabContents* tab_contents = browser()->GetSelectedTabContents();
+ TabContents* tab_contents = browser->GetSelectedTabContents();
WebContextMenuData data;
ContextMenuParams params(data);
params.page_url = page_url;
@@ -173,7 +181,8 @@ class ExtensionContextMenuBrowserTest : public ExtensionBrowserTest {
bool MenuHasItemWithLabel(const GURL& page_url,
const GURL& link_url,
const std::string& label) {
- scoped_ptr<TestRenderViewContextMenu> menu(CreateMenu(page_url, link_url));
+ scoped_ptr<TestRenderViewContextMenu> menu(
+ CreateMenu(browser(), page_url, link_url));
return menu->HasExtensionItemWithLabel(label);
}
};
@@ -190,7 +199,8 @@ IN_PROC_BROWSER_TEST_F(ExtensionContextMenuBrowserTest, Simple) {
GURL page_url("http://www.google.com");
// Create and build our test context menu.
- scoped_ptr<TestRenderViewContextMenu> menu(CreateMenu(page_url, GURL()));
+ scoped_ptr<TestRenderViewContextMenu> menu(
+ CreateMenu(browser(), page_url, GURL()));
// Look for the extension item in the menu, and execute it.
int command_id = IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST;
@@ -249,7 +259,8 @@ IN_PROC_BROWSER_TEST_F(ExtensionContextMenuBrowserTest, LongTitle) {
// Create a context menu, then find the item's label. It should be properly
// truncated.
GURL url("http://foo.com/");
- scoped_ptr<TestRenderViewContextMenu> menu(CreateMenu(url, GURL()));
+ scoped_ptr<TestRenderViewContextMenu> menu(
+ CreateMenu(browser(), url, GURL()));
string16 label;
ASSERT_TRUE(menu->GetItemLabel(item->id(), &label));
@@ -313,7 +324,8 @@ IN_PROC_BROWSER_TEST_F(ExtensionContextMenuBrowserTest, Separators) {
listener1.WaitUntilSatisfied();
GURL url("http://www.google.com/");
- scoped_ptr<TestRenderViewContextMenu> menu(CreateMenu(url, GURL()));
+ scoped_ptr<TestRenderViewContextMenu> menu(
+ CreateMenu(browser(), url, GURL()));
// The top-level item should be an "automagic parent" with the extension's
// name.
@@ -336,7 +348,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionContextMenuBrowserTest, Separators) {
ui_test_utils::NavigateToURL(browser(),
GURL(extension->GetResourceURL("test2.html")));
listener2.WaitUntilSatisfied();
- menu.reset(CreateMenu(url, GURL()));
+ menu.reset(CreateMenu(browser(), url, GURL()));
ASSERT_TRUE(menu->GetMenuModelAndItemIndex(
IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST, &model, &index));
EXPECT_EQ(UTF8ToUTF16("parent"), model->GetLabelAt(index));
@@ -368,3 +380,50 @@ IN_PROC_BROWSER_TEST_F(ExtensionContextMenuBrowserTest, TargetURLs) {
non_google_url,
std::string("item1")));
}
+
+// Tests adding a simple context menu item.
+IN_PROC_BROWSER_TEST_F(ExtensionContextMenuBrowserTest, IncognitoSplit) {
+ ExtensionTestMessageListener created("created item regular", false);
+ ExtensionTestMessageListener created_incognito("created item incognito",
+ false);
+
+ ExtensionTestMessageListener onclick("onclick fired regular", false);
+ ExtensionTestMessageListener onclick_incognito("onclick fired incognito",
+ false);
+
+ // Open an incognito window.
+ ui_test_utils::OpenURLOffTheRecord(browser()->profile(), GURL("about:blank"));
+
+ ASSERT_TRUE(LoadContextMenuExtensionIncognito("incognito"));
+
+ // Wait for the extension's processes to tell us they've created an item.
+ ASSERT_TRUE(created.WaitUntilSatisfied());
+ ASSERT_TRUE(created_incognito.WaitUntilSatisfied());
+
+ GURL page_url("http://www.google.com");
+
+ // Create and build our test context menu.
+ Browser* browser_incognito = BrowserList::FindBrowserWithType(
+ browser()->profile()->GetOffTheRecordProfile(),
+ Browser::TYPE_NORMAL, false);
+ ASSERT_TRUE(browser_incognito);
+ scoped_ptr<TestRenderViewContextMenu> menu(
+ CreateMenu(browser(), page_url, GURL()));
+ scoped_ptr<TestRenderViewContextMenu> menu_incognito(
+ CreateMenu(browser_incognito, page_url, GURL()));
+
+ // Look for the extension item in the menu, and execute it.
+ int command_id = IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST;
+ ASSERT_TRUE(menu->IsCommandIdEnabled(command_id));
+ menu->ExecuteCommand(command_id);
+
+ // Wait for the extension's script to tell us its onclick fired. Ensure
+ // that the incognito version doesn't fire until we explicitly click the
+ // incognito menu item.
+ ASSERT_TRUE(onclick.WaitUntilSatisfied());
+ EXPECT_FALSE(onclick_incognito.was_satisfied());
+
+ ASSERT_TRUE(menu_incognito->IsCommandIdEnabled(command_id));
+ menu_incognito->ExecuteCommand(command_id);
+ ASSERT_TRUE(onclick_incognito.WaitUntilSatisfied());
+}