summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions
diff options
context:
space:
mode:
authoryoz@chromium.org <yoz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-01 23:56:38 +0000
committeryoz@chromium.org <yoz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-01 23:56:38 +0000
commit158ce095aef6fc54ae69e568263fd0db60b85489 (patch)
tree8bd4f9bdcfbec4839f273a56e5fd9733762e01d3 /chrome/browser/extensions
parentab55c2b682d9770de2b46cc85b00bcc79c4ea315 (diff)
downloadchromium_src-158ce095aef6fc54ae69e568263fd0db60b85489.zip
chromium_src-158ce095aef6fc54ae69e568263fd0db60b85489.tar.gz
chromium_src-158ce095aef6fc54ae69e568263fd0db60b85489.tar.bz2
Browser test for executing context menu items from event pages.
BUG=123366 Review URL: https://chromiumcodereview.appspot.com/10476004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@140129 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions')
-rw-r--r--chrome/browser/extensions/extension_context_menu_browsertest.cc74
-rw-r--r--chrome/browser/extensions/lazy_background_page_apitest.cc34
-rw-r--r--chrome/browser/extensions/lazy_background_page_test_util.h45
3 files changed, 106 insertions, 47 deletions
diff --git a/chrome/browser/extensions/extension_context_menu_browsertest.cc b/chrome/browser/extensions/extension_context_menu_browsertest.cc
index c4e06d4..975cc06 100644
--- a/chrome/browser/extensions/extension_context_menu_browsertest.cc
+++ b/chrome/browser/extensions/extension_context_menu_browsertest.cc
@@ -7,10 +7,12 @@
#include "chrome/browser/extensions/extension_browsertest.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_test_message_listener.h"
+#include "chrome/browser/extensions/lazy_background_page_test_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/tab_contents/render_view_context_menu.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
+#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/common/context_menu_params.h"
#include "net/base/mock_host_resolver.h"
@@ -89,18 +91,6 @@ class TestRenderViewContextMenu : public RenderViewContextMenu {
return false;
}
- protected:
- // These two functions implement pure virtual methods of
- // RenderViewContextMenu.
- virtual bool GetAcceleratorForCommandId(int command_id,
- ui::Accelerator* accelerator) {
- // None of our commands have accelerators, so always return false.
- return false;
- }
- virtual void PlatformInit() {}
- virtual void PlatformCancel() {}
-
-
// Given an extension menu item id, tries to find the corresponding command id
// in the menu.
bool FindCommandId(const ExtensionMenuItem::Id& id, int* command_id) {
@@ -113,6 +103,17 @@ class TestRenderViewContextMenu : public RenderViewContextMenu {
}
return false;
}
+
+ protected:
+ // These two functions implement pure virtual methods of
+ // RenderViewContextMenu.
+ virtual bool GetAcceleratorForCommandId(int command_id,
+ ui::Accelerator* accelerator) {
+ // None of our commands have accelerators, so always return false.
+ return false;
+ }
+ virtual void PlatformInit() {}
+ virtual void PlatformCancel() {}
};
} // namespace
@@ -121,13 +122,15 @@ class ExtensionContextMenuBrowserTest : public ExtensionBrowserTest {
public:
// Helper to load an extension from context_menus/|subdirectory| in the
// extensions test data dir.
- bool LoadContextMenuExtension(std::string subdirectory) {
+ const extensions::Extension* LoadContextMenuExtension(
+ std::string subdirectory) {
FilePath extension_dir =
test_data_dir_.AppendASCII("context_menus").AppendASCII(subdirectory);
return LoadExtension(extension_dir);
}
- bool LoadContextMenuExtensionIncognito(std::string subdirectory) {
+ const extensions::Extension* LoadContextMenuExtensionIncognito(
+ std::string subdirectory) {
FilePath extension_dir =
test_data_dir_.AppendASCII("context_menus").AppendASCII(subdirectory);
return LoadExtensionIncognito(extension_dir);
@@ -508,3 +511,46 @@ IN_PROC_BROWSER_TEST_F(ExtensionContextMenuBrowserTest, Enabled) {
TestEnabledContextMenu(true);
TestEnabledContextMenu(false);
}
+
+class ExtensionContextMenuBrowserLazyTest :
+ public ExtensionContextMenuBrowserTest {
+ void SetUpCommandLine(CommandLine* command_line) {
+ ExtensionContextMenuBrowserTest::SetUpCommandLine(command_line);
+ // Set shorter delays to prevent test timeouts.
+ command_line->AppendSwitchASCII(switches::kEventPageIdleTime, "0");
+ command_line->AppendSwitchASCII(switches::kEventPageUnloadingTime, "0");
+ }
+};
+
+IN_PROC_BROWSER_TEST_F(ExtensionContextMenuBrowserLazyTest, EventPage) {
+ GURL about_blank("about:blank");
+ LazyBackgroundObserver page_complete;
+ const extensions::Extension* extension = LoadContextMenuExtension(
+ "event_page");
+ ASSERT_TRUE(extension);
+ page_complete.Wait();
+
+ // Test that menu items appear while the page is unloaded.
+ ASSERT_TRUE(MenuHasItemWithLabel(
+ about_blank, GURL(), GURL(), std::string("Item 1")));
+ ASSERT_TRUE(MenuHasItemWithLabel(
+ about_blank, GURL(), GURL(), std::string("Checkbox 1")));
+
+ // Test that checked menu items retain their checkedness.
+ LazyBackgroundObserver checkbox_checked;
+ scoped_ptr<TestRenderViewContextMenu> menu(
+ CreateMenu(browser(), about_blank, GURL(), GURL()));
+ ExtensionMenuItem::Id id(false, extension->id());
+ id.string_uid = "checkbox1";
+ int command_id = -1;
+ ASSERT_TRUE(menu->FindCommandId(id, &command_id));
+ EXPECT_FALSE(menu->IsCommandIdChecked(command_id));
+
+ // Executing the checkbox also fires the onClicked event.
+ ExtensionTestMessageListener listener("onClicked fired for checkbox1", false);
+ menu->ExecuteCommand(command_id);
+ checkbox_checked.WaitUntilClosed();
+
+ EXPECT_TRUE(menu->IsCommandIdChecked(command_id));
+ ASSERT_TRUE(listener.WaitUntilSatisfied());
+}
diff --git a/chrome/browser/extensions/lazy_background_page_apitest.cc b/chrome/browser/extensions/lazy_background_page_apitest.cc
index d257fcc..5142edb 100644
--- a/chrome/browser/extensions/lazy_background_page_apitest.cc
+++ b/chrome/browser/extensions/lazy_background_page_apitest.cc
@@ -12,6 +12,7 @@
#include "chrome/browser/extensions/extension_host.h"
#include "chrome/browser/extensions/extension_test_message_listener.h"
#include "chrome/browser/extensions/extension_service.h"
+#include "chrome/browser/extensions/lazy_background_page_test_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
@@ -29,37 +30,6 @@
using extensions::Extension;
namespace {
-// Helper class to wait for a lazy background page to load and close again.
-class LazyBackgroundObserver {
- public:
- LazyBackgroundObserver()
- : page_created_(chrome::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY,
- content::NotificationService::AllSources()),
- page_closed_(chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
- content::NotificationService::AllSources()) {
- }
- explicit LazyBackgroundObserver(Profile* profile)
- : page_created_(chrome::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY,
- content::NotificationService::AllSources()),
- page_closed_(chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
- content::Source<Profile>(profile)) {
- }
- void Wait() {
- page_created_.Wait();
- page_closed_.Wait();
- }
-
- void WaitUntilLoaded() {
- page_created_.Wait();
- }
- void WaitUntilClosed() {
- page_closed_.Wait();
- }
-
- private:
- ui_test_utils::WindowedNotificationObserver page_created_;
- ui_test_utils::WindowedNotificationObserver page_closed_;
-};
// This unfortunate bit of silliness is necessary when loading an extension in
// incognito. The goal is to load the extension, enable incognito, then wait
@@ -97,7 +67,6 @@ class LoadedIncognitoObserver : public content::NotificationObserver {
scoped_ptr<LazyBackgroundObserver> incognito_complete_;
};
-
} // namespace
class LazyBackgroundPageApiTest : public ExtensionApiTest {
@@ -390,4 +359,3 @@ IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, OnUnload) {
// TODO: background page with timer.
// TODO: background page that interacts with popup.
-// TODO: background page with menu.
diff --git a/chrome/browser/extensions/lazy_background_page_test_util.h b/chrome/browser/extensions/lazy_background_page_test_util.h
new file mode 100644
index 0000000..88e3540
--- /dev/null
+++ b/chrome/browser/extensions/lazy_background_page_test_util.h
@@ -0,0 +1,45 @@
+// Copyright (c) 2012 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.
+
+#ifndef CHROME_BROWSER_EXTENSIONS_LAZY_BACKGROUND_PAGE_TEST_UTIL_H_
+#define CHROME_BROWSER_EXTENSIONS_LAZY_BACKGROUND_PAGE_TEST_UTIL_H_
+#pragma once
+
+#include "content/public/browser/notification_service.h"
+#include "chrome/common/chrome_notification_types.h"
+#include "chrome/test/base/ui_test_utils.h"
+
+// Helper class to wait for a lazy background page to load and close again.
+class LazyBackgroundObserver {
+ public:
+ LazyBackgroundObserver()
+ : page_created_(chrome::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY,
+ content::NotificationService::AllSources()),
+ page_closed_(chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
+ content::NotificationService::AllSources()) {
+ }
+ explicit LazyBackgroundObserver(Profile* profile)
+ : page_created_(chrome::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY,
+ content::NotificationService::AllSources()),
+ page_closed_(chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
+ content::Source<Profile>(profile)) {
+ }
+ void Wait() {
+ page_created_.Wait();
+ page_closed_.Wait();
+ }
+
+ void WaitUntilLoaded() {
+ page_created_.Wait();
+ }
+ void WaitUntilClosed() {
+ page_closed_.Wait();
+ }
+
+ private:
+ ui_test_utils::WindowedNotificationObserver page_created_;
+ ui_test_utils::WindowedNotificationObserver page_closed_;
+};
+
+#endif // CHROME_BROWSER_EXTENSIONS_LAZY_BACKGROUND_PAGE_TEST_UTIL_H_