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

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

Issue 10828172: Allow platform apps to respond to Web Intents (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Adds basic test Created 8 years, 3 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
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 "base/bind.h"
6 #include "base/utf_string_conversions.h"
5 #include "chrome/app/chrome_command_ids.h" 7 #include "chrome/app/chrome_command_ids.h"
6 #include "chrome/browser/automation/automation_util.h" 8 #include "chrome/browser/automation/automation_util.h"
7 #include "chrome/browser/tab_contents/render_view_context_menu.h" 9 #include "chrome/browser/tab_contents/render_view_context_menu.h"
10 #include "chrome/browser/extensions/extension_browsertest.h"
8 #include "chrome/browser/extensions/extension_test_message_listener.h" 11 #include "chrome/browser/extensions/extension_test_message_listener.h"
9 #include "chrome/browser/extensions/platform_app_browsertest_util.h" 12 #include "chrome/browser/extensions/platform_app_browsertest_util.h"
13 #include "chrome/browser/extensions/platform_app_launcher.h"
10 #include "chrome/browser/extensions/shell_window_registry.h" 14 #include "chrome/browser/extensions/shell_window_registry.h"
11 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/browser_tabstrip.h" 16 #include "chrome/browser/ui/browser_tabstrip.h"
13 #include "chrome/browser/ui/extensions/application_launch.h" 17 #include "chrome/browser/ui/extensions/application_launch.h"
14 #include "chrome/browser/ui/extensions/shell_window.h" 18 #include "chrome/browser/ui/extensions/shell_window.h"
15 #include "chrome/common/chrome_notification_types.h" 19 #include "chrome/common/chrome_notification_types.h"
16 #include "chrome/test/base/ui_test_utils.h" 20 #include "chrome/test/base/ui_test_utils.h"
17 #include "content/public/browser/render_process_host.h" 21 #include "content/public/browser/render_process_host.h"
22 #include "content/public/browser/web_intents_dispatcher.h"
23 #include "googleurl/src/gurl.h"
24 #include "webkit/glue/web_intent_data.h"
18 25
19 using content::WebContents; 26 using content::WebContents;
20 27
21 namespace extensions { 28 namespace extensions {
22 29
23 namespace { 30 namespace {
24 // Non-abstract RenderViewContextMenu class. 31 // Non-abstract RenderViewContextMenu class.
25 class PlatformAppContextMenu : public RenderViewContextMenu { 32 class PlatformAppContextMenu : public RenderViewContextMenu {
26 public: 33 public:
27 PlatformAppContextMenu(WebContents* web_contents, 34 PlatformAppContextMenu(WebContents* web_contents,
28 const content::ContextMenuParams& params) 35 const content::ContextMenuParams& params)
29 : RenderViewContextMenu(web_contents, params) {} 36 : RenderViewContextMenu(web_contents, params) {}
30 37
31 bool HasCommandWithId(int command_id) { 38 bool HasCommandWithId(int command_id) {
32 return menu_model_.GetIndexOfCommandId(command_id) != -1; 39 return menu_model_.GetIndexOfCommandId(command_id) != -1;
33 } 40 }
34 41
35 protected: 42 protected:
36 // These two functions implement pure virtual methods of 43 // These two functions implement pure virtual methods of
37 // RenderViewContextMenu. 44 // RenderViewContextMenu.
38 virtual bool GetAcceleratorForCommandId(int command_id, 45 virtual bool GetAcceleratorForCommandId(int command_id,
39 ui::Accelerator* accelerator) { 46 ui::Accelerator* accelerator) {
40 return false; 47 return false;
41 } 48 }
42 virtual void PlatformInit() {} 49 virtual void PlatformInit() {}
43 virtual void PlatformCancel() {} 50 virtual void PlatformCancel() {}
44 }; 51 };
45 52
53 // State holder for the LaunchReply test. This provides an WebIntentsDispatcher
54 // that will, when used to launch a Web Intent, will return its reply via this
55 // class. The result may then be waited on via WaitUntilReply().
56 class LaunchReplyHandler {
57 public:
58 explicit LaunchReplyHandler(webkit_glue::WebIntentData& data)
59 : data_(data),
60 replied_(false),
61 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
62 intents_dispatcher_ = content::WebIntentsDispatcher::Create(data);
63 intents_dispatcher_->RegisterReplyNotification(base::Bind(
64 &LaunchReplyHandler::OnReply, weak_ptr_factory_.GetWeakPtr()));
65 }
66
67 content::WebIntentsDispatcher* intents_dispatcher() {
benwells 2012/08/29 12:19:21 nit: indenting
thorogood 2012/08/30 02:37:42 Done.
68 return intents_dispatcher_;
69 }
70
71 // Waits until a reply to this Web Intent is provided via the
72 // WebIntentsDispatcher.
73 bool WaitUntilReply() {
74 if (replied_)
75 return true;
76 waiting_ = true;
benwells 2012/08/29 12:19:21 I am not sure if the threading model in tests is t
thorogood 2012/08/30 02:37:42 Naively, I tend to actually agree with you -- I've
benwells 2012/08/30 04:29:07 Ah ok, if both functions always run in the same th
77 content::RunMessageLoop();
78 waiting_ = false;
79 return replied_;
80 }
81
82 private:
83 void OnReply(webkit_glue::WebIntentReplyType reply) {
84 // Note that the ReplyNotification registered on WebIntentsDispatcher does
85 // not include the result data: this is reserved for the source page (which
86 // we don't care about).
87 replied_ = true;
88 if (waiting_)
89 MessageLoopForUI::current()->Quit();
90 }
91
92 webkit_glue::WebIntentData data_;
93 bool replied_;
94 bool waiting_;
95 content::WebIntentsDispatcher* intents_dispatcher_;
96 base::WeakPtrFactory<LaunchReplyHandler> weak_ptr_factory_;
97 };
98
46 } // namespace 99 } // namespace
47 100
48 // Tests that CreateShellWindow doesn't crash if you close it straight away. 101 // Tests that CreateShellWindow doesn't crash if you close it straight away.
49 // LauncherPlatformAppBrowserTest relies on this behaviour, but is only run for 102 // LauncherPlatformAppBrowserTest relies on this behaviour, but is only run for
50 // ash, so we test that it works here. 103 // ash, so we test that it works here.
51 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, CreateAndCloseShellWindow) { 104 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, CreateAndCloseShellWindow) {
52 const Extension* extension = LoadAndLaunchPlatformApp("minimal"); 105 const Extension* extension = LoadAndLaunchPlatformApp("minimal");
53 ShellWindow* window = CreateShellWindow(extension); 106 ShellWindow* window = CreateShellWindow(extension);
54 CloseShellWindow(window); 107 CloseShellWindow(window);
55 } 108 }
56 109
57 // Tests that platform apps received the "launch" event when launched. 110 // Tests that platform apps received the "launch" event when launched.
58 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, OnLaunchedEvent) { 111 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, OnLaunchedEvent) {
59 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch")) << message_; 112 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch")) << message_;
60 } 113 }
61 114
115 // Tests that platform apps can reply to "launch" events that contain a Web
benwells 2012/08/29 12:19:21 It's great that this is tested! It would be even b
thorogood 2012/08/30 02:37:42 Thanks! Yep, I'll happily follow this up.
116 // Intent. This test does not test the mechanics of invoking a Web Intent
117 // from a source page, and short-circuits to LaunchPlatformAppWithWebIntent.
118 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchReply) {
119 FilePath path = test_data_dir_.AppendASCII("platform_apps/launch_reply");
120 const extensions::Extension* extension = LoadExtension(path);
121 ASSERT_TRUE(extension) << "Failed to load extension.";
122
123 webkit_glue::WebIntentData data(
124 UTF8ToUTF16("http://webintents.org/view"),
125 UTF8ToUTF16("text/plain"),
126 UTF8ToUTF16("irrelevant unserialized string data"));
127 LaunchReplyHandler handler(data);
128
129 // Navigate to a boring page: we don't care what it is, but we require some
130 // source WebContents to launch the Web Intent "from".
131 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
132 WebContents* web_contents = chrome::GetActiveWebContents(browser());
133 ASSERT_TRUE(web_contents);
134
135 extensions::LaunchPlatformAppWithWebIntent(
136 browser()->profile(),
137 extension,
138 handler.intents_dispatcher(),
139 web_contents);
140
141 ASSERT_TRUE(handler.WaitUntilReply());
142 }
143
62 // Tests that platform apps cannot use certain disabled window properties, but 144 // Tests that platform apps cannot use certain disabled window properties, but
63 // can override them and then use them. 145 // can override them and then use them.
64 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisabledWindowProperties) { 146 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisabledWindowProperties) {
65 ASSERT_TRUE(RunPlatformAppTest("platform_apps/disabled_window_properties")) 147 ASSERT_TRUE(RunPlatformAppTest("platform_apps/disabled_window_properties"))
66 << message_; 148 << message_;
67 } 149 }
68 150
69 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, EmptyContextMenu) { 151 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, EmptyContextMenu) {
70 ExtensionTestMessageListener launched_listener("Launched", false); 152 ExtensionTestMessageListener launched_listener("Launched", false);
71 LoadAndLaunchPlatformApp("minimal"); 153 LoadAndLaunchPlatformApp("minimal");
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 LoadAndLaunchPlatformApp("open_link"); 429 LoadAndLaunchPlatformApp("open_link");
348 observer.Wait(); 430 observer.Wait();
349 ASSERT_EQ(2, browser()->tab_count()); 431 ASSERT_EQ(2, browser()->tab_count());
350 } 432 }
351 433
352 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, MutationEventsDisabled) { 434 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, MutationEventsDisabled) {
353 ASSERT_TRUE(RunPlatformAppTest("platform_apps/mutation_events")) << message_; 435 ASSERT_TRUE(RunPlatformAppTest("platform_apps/mutation_events")) << message_;
354 } 436 }
355 437
356 } // namespace extensions 438 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698