Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(407)

Side by Side Diff: chrome/browser/extensions/platform_app_browsertest.cc

Issue 10539060: Make platform app context menu browser tests more resilient. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/app/chrome_command_ids.h"
5 #include "chrome/browser/automation/automation_util.h" 6 #include "chrome/browser/automation/automation_util.h"
6 #include "chrome/browser/tab_contents/render_view_context_menu.h" 7 #include "chrome/browser/tab_contents/render_view_context_menu.h"
7 #include "chrome/browser/extensions/extension_test_message_listener.h" 8 #include "chrome/browser/extensions/extension_test_message_listener.h"
8 #include "chrome/browser/extensions/platform_app_browsertest_util.h" 9 #include "chrome/browser/extensions/platform_app_browsertest_util.h"
9 #include "chrome/browser/extensions/shell_window_registry.h" 10 #include "chrome/browser/extensions/shell_window_registry.h"
10 #include "chrome/browser/ui/browser.h" 11 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/extensions/shell_window.h" 12 #include "chrome/browser/ui/extensions/shell_window.h"
12 #include "chrome/test/base/ui_test_utils.h" 13 #include "chrome/test/base/ui_test_utils.h"
13 14
14 using content::WebContents; 15 using content::WebContents;
15 using extensions::Extension; 16 using extensions::Extension;
16 17
17 namespace { 18 namespace {
18 // Non-abstract RenderViewContextMenu class. 19 // Non-abstract RenderViewContextMenu class.
19 class PlatformAppContextMenu : public RenderViewContextMenu { 20 class PlatformAppContextMenu : public RenderViewContextMenu {
20 public: 21 public:
21 PlatformAppContextMenu(WebContents* web_contents, 22 PlatformAppContextMenu(WebContents* web_contents,
22 const content::ContextMenuParams& params) 23 const content::ContextMenuParams& params)
23 : RenderViewContextMenu(web_contents, params) {} 24 : RenderViewContextMenu(web_contents, params) {}
24 25
26 bool HasCommandWithId(int command_id) {
27 return menu_model_.GetIndexOfCommandId(command_id) != -1;
28 }
29
25 protected: 30 protected:
26 // These two functions implement pure virtual methods of 31 // These two functions implement pure virtual methods of
27 // RenderViewContextMenu. 32 // RenderViewContextMenu.
28 virtual bool GetAcceleratorForCommandId(int command_id, 33 virtual bool GetAcceleratorForCommandId(int command_id,
29 ui::Accelerator* accelerator) { 34 ui::Accelerator* accelerator) {
30 return false; 35 return false;
31 } 36 }
32 virtual void PlatformInit() {} 37 virtual void PlatformInit() {}
33 virtual void PlatformCancel() {} 38 virtual void PlatformCancel() {}
34 }; 39 };
(...skipping 13 matching lines...) Expand all
48 53
49 // The empty app doesn't add any context menu items, so its menu should 54 // The empty app doesn't add any context menu items, so its menu should
50 // only include the developer tools. 55 // only include the developer tools.
51 WebContents* web_contents = GetFirstShellWindowWebContents(); 56 WebContents* web_contents = GetFirstShellWindowWebContents();
52 ASSERT_TRUE(web_contents); 57 ASSERT_TRUE(web_contents);
53 WebKit::WebContextMenuData data; 58 WebKit::WebContextMenuData data;
54 content::ContextMenuParams params(data); 59 content::ContextMenuParams params(data);
55 PlatformAppContextMenu* menu = new PlatformAppContextMenu(web_contents, 60 PlatformAppContextMenu* menu = new PlatformAppContextMenu(web_contents,
56 params); 61 params);
57 menu->Init(); 62 menu->Init();
58 // TODO(benwells): Remove the constant below. Instead of checking the 63 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT));
59 // number of menu items check certain item's absense and presence. 64 ASSERT_TRUE(menu->HasCommandWithId(IDC_RELOAD));
60 // 3 including separator 65 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK));
61 ASSERT_EQ(3, menu->menu_model().GetItemCount()); 66 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE));
62 } 67 }
63 68
64 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenu) { 69 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenu) {
65 ExtensionTestMessageListener launched_listener("Launched", false); 70 ExtensionTestMessageListener launched_listener("Launched", false);
66 LoadAndLaunchPlatformApp("context_menu"); 71 LoadAndLaunchPlatformApp("context_menu");
67 72
68 // Wait for the extension to tell us it's initialized its context menus and 73 // Wait for the extension to tell us it's initialized its context menus and
69 // launched a window. 74 // launched a window.
70 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); 75 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
71 76
72 // The context_menu app has one context menu item. This, along with a 77 // The context_menu app has one context menu item. This, along with a
73 // separator and the developer tools, is all that should be in the menu. 78 // separator and the developer tools, is all that should be in the menu.
74 WebContents* web_contents = GetFirstShellWindowWebContents(); 79 WebContents* web_contents = GetFirstShellWindowWebContents();
75 ASSERT_TRUE(web_contents); 80 ASSERT_TRUE(web_contents);
76 WebKit::WebContextMenuData data; 81 WebKit::WebContextMenuData data;
77 content::ContextMenuParams params(data); 82 content::ContextMenuParams params(data);
78 PlatformAppContextMenu* menu = new PlatformAppContextMenu(web_contents, 83 PlatformAppContextMenu* menu = new PlatformAppContextMenu(web_contents,
79 params); 84 params);
80 menu->Init(); 85 menu->Init();
81 // TODO(benwells): Remove the constant below. Instead of checking the 86 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST));
82 // number of menu items check certain item's absense and presence. 87 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT));
83 ASSERT_EQ(4, menu->menu_model().GetItemCount()); 88 ASSERT_TRUE(menu->HasCommandWithId(IDC_RELOAD));
89 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK));
90 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE));
84 } 91 }
85 92
86 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisallowNavigation) { 93 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisallowNavigation) {
87 ASSERT_TRUE(StartTestServer()); 94 ASSERT_TRUE(StartTestServer());
88 ASSERT_TRUE(RunPlatformAppTest("platform_apps/navigation")) << message_; 95 ASSERT_TRUE(RunPlatformAppTest("platform_apps/navigation")) << message_;
89 } 96 }
90 97
91 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, Iframes) { 98 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, Iframes) {
92 ASSERT_TRUE(StartTestServer()); 99 ASSERT_TRUE(StartTestServer());
93 ASSERT_TRUE(RunPlatformAppTest("platform_apps/iframes")) << message_; 100 ASSERT_TRUE(RunPlatformAppTest("platform_apps/iframes")) << message_;
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 250
244 // Test that platform apps can use the chrome.fileSystem.getDisplayPath 251 // Test that platform apps can use the chrome.fileSystem.getDisplayPath
245 // function to get the native file system path of a file they are launched with. 252 // function to get the native file system path of a file they are launched with.
246 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, GetDisplayPath) { 253 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, GetDisplayPath) {
247 SetCommandLineArg("platform_apps/launch_files/test.txt"); 254 SetCommandLineArg("platform_apps/launch_files/test.txt");
248 ASSERT_TRUE(RunPlatformAppTest("platform_apps/get_display_path")) 255 ASSERT_TRUE(RunPlatformAppTest("platform_apps/get_display_path"))
249 << message_; 256 << message_;
250 } 257 }
251 258
252 #endif // defined(OS_CHROMEOS) 259 #endif // defined(OS_CHROMEOS)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698