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

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: about to submit 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"
5 #include "base/test/test_timeouts.h" 6 #include "base/test/test_timeouts.h"
6 #include "base/threading/platform_thread.h" 7 #include "base/threading/platform_thread.h"
7 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
8 #include "chrome/app/chrome_command_ids.h" 9 #include "chrome/app/chrome_command_ids.h"
9 #include "chrome/browser/automation/automation_util.h" 10 #include "chrome/browser/automation/automation_util.h"
10 #include "chrome/browser/tab_contents/render_view_context_menu.h" 11 #include "chrome/browser/tab_contents/render_view_context_menu.h"
12 #include "chrome/browser/extensions/extension_browsertest.h"
11 #include "chrome/browser/extensions/extension_test_message_listener.h" 13 #include "chrome/browser/extensions/extension_test_message_listener.h"
12 #include "chrome/browser/extensions/platform_app_browsertest_util.h" 14 #include "chrome/browser/extensions/platform_app_browsertest_util.h"
15 #include "chrome/browser/extensions/platform_app_launcher.h"
13 #include "chrome/browser/extensions/shell_window_registry.h" 16 #include "chrome/browser/extensions/shell_window_registry.h"
14 #include "chrome/browser/ui/browser.h" 17 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/browser_tabstrip.h" 18 #include "chrome/browser/ui/browser_tabstrip.h"
16 #include "chrome/browser/ui/extensions/application_launch.h" 19 #include "chrome/browser/ui/extensions/application_launch.h"
17 #include "chrome/browser/ui/extensions/shell_window.h" 20 #include "chrome/browser/ui/extensions/shell_window.h"
18 #include "chrome/common/chrome_notification_types.h" 21 #include "chrome/common/chrome_notification_types.h"
19 #include "chrome/test/base/ui_test_utils.h" 22 #include "chrome/test/base/ui_test_utils.h"
20 #include "content/public/browser/render_process_host.h" 23 #include "content/public/browser/render_process_host.h"
24 #include "content/public/browser/web_intents_dispatcher.h"
25 #include "googleurl/src/gurl.h"
26 #include "webkit/glue/web_intent_data.h"
21 27
22 using content::WebContents; 28 using content::WebContents;
23 29
24 namespace extensions { 30 namespace extensions {
25 31
26 namespace { 32 namespace {
27 33
28 // Non-abstract RenderViewContextMenu class. 34 // Non-abstract RenderViewContextMenu class.
29 class PlatformAppContextMenu : public RenderViewContextMenu { 35 class PlatformAppContextMenu : public RenderViewContextMenu {
30 public: 36 public:
31 PlatformAppContextMenu(WebContents* web_contents, 37 PlatformAppContextMenu(WebContents* web_contents,
32 const content::ContextMenuParams& params) 38 const content::ContextMenuParams& params)
33 : RenderViewContextMenu(web_contents, params) {} 39 : RenderViewContextMenu(web_contents, params) {}
34 40
35 bool HasCommandWithId(int command_id) { 41 bool HasCommandWithId(int command_id) {
36 return menu_model_.GetIndexOfCommandId(command_id) != -1; 42 return menu_model_.GetIndexOfCommandId(command_id) != -1;
37 } 43 }
38 44
39 protected: 45 protected:
40 // RenderViewContextMenu implementation. 46 // RenderViewContextMenu implementation.
41 virtual bool GetAcceleratorForCommandId( 47 virtual bool GetAcceleratorForCommandId(
42 int command_id, 48 int command_id,
43 ui::Accelerator* accelerator) OVERRIDE { 49 ui::Accelerator* accelerator) OVERRIDE {
44 return false; 50 return false;
45 } 51 }
46 virtual void PlatformInit() OVERRIDE {} 52 virtual void PlatformInit() OVERRIDE {}
47 virtual void PlatformCancel() OVERRIDE {} 53 virtual void PlatformCancel() OVERRIDE {}
48 }; 54 };
49 55
56 // State holder for the LaunchReply test. This provides an WebIntentsDispatcher
57 // that will, when used to launch a Web Intent, will return its reply via this
58 // class. The result may then be waited on via WaitUntilReply().
59 class LaunchReplyHandler {
60 public:
61 explicit LaunchReplyHandler(webkit_glue::WebIntentData& data)
62 : data_(data),
63 replied_(false),
64 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
65 intents_dispatcher_ = content::WebIntentsDispatcher::Create(data);
66 intents_dispatcher_->RegisterReplyNotification(base::Bind(
67 &LaunchReplyHandler::OnReply, weak_ptr_factory_.GetWeakPtr()));
68 }
69
70 content::WebIntentsDispatcher* intents_dispatcher() {
71 return intents_dispatcher_;
72 }
73
74 // Waits until a reply to this Web Intent is provided via the
75 // WebIntentsDispatcher.
76 bool WaitUntilReply() {
77 if (replied_)
78 return true;
79 waiting_ = true;
80 content::RunMessageLoop();
81 waiting_ = false;
82 return replied_;
83 }
84
85 private:
86 void OnReply(webkit_glue::WebIntentReplyType reply) {
87 // Note that the ReplyNotification registered on WebIntentsDispatcher does
88 // not include the result data: this is reserved for the source page (which
89 // we don't care about).
90 replied_ = true;
91 if (waiting_)
92 MessageLoopForUI::current()->Quit();
93 }
94
95 webkit_glue::WebIntentData data_;
96 bool replied_;
97 bool waiting_;
98 content::WebIntentsDispatcher* intents_dispatcher_;
99 base::WeakPtrFactory<LaunchReplyHandler> weak_ptr_factory_;
100 };
101
50 const char kTestFilePath[] = "platform_apps/launch_files/test.txt"; 102 const char kTestFilePath[] = "platform_apps/launch_files/test.txt";
51 103
52 } // namespace 104 } // namespace
53 105
54 // Tests that CreateShellWindow doesn't crash if you close it straight away. 106 // Tests that CreateShellWindow doesn't crash if you close it straight away.
55 // LauncherPlatformAppBrowserTest relies on this behaviour, but is only run for 107 // LauncherPlatformAppBrowserTest relies on this behaviour, but is only run for
56 // ash, so we test that it works here. 108 // ash, so we test that it works here.
57 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, CreateAndCloseShellWindow) { 109 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, CreateAndCloseShellWindow) {
58 const Extension* extension = LoadAndLaunchPlatformApp("minimal"); 110 const Extension* extension = LoadAndLaunchPlatformApp("minimal");
59 ShellWindow* window = CreateShellWindow(extension); 111 ShellWindow* window = CreateShellWindow(extension);
60 CloseShellWindow(window); 112 CloseShellWindow(window);
61 } 113 }
62 114
63 // Tests that platform apps received the "launch" event when launched. 115 // Tests that platform apps received the "launch" event when launched.
64 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, OnLaunchedEvent) { 116 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, OnLaunchedEvent) {
65 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch")) << message_; 117 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch")) << message_;
66 } 118 }
67 119
120 // Tests that platform apps can reply to "launch" events that contain a Web
121 // Intent. This test does not test the mechanics of invoking a Web Intent
122 // from a source page, and short-circuits to LaunchPlatformAppWithWebIntent.
123 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchReply) {
124 FilePath path = test_data_dir_.AppendASCII("platform_apps/launch_reply");
125 const extensions::Extension* extension = LoadExtension(path);
126 ASSERT_TRUE(extension) << "Failed to load extension.";
127
128 webkit_glue::WebIntentData data(
129 UTF8ToUTF16("http://webintents.org/view"),
130 UTF8ToUTF16("text/plain"),
131 UTF8ToUTF16("irrelevant unserialized string data"));
132 LaunchReplyHandler handler(data);
133
134 // Navigate to a boring page: we don't care what it is, but we require some
135 // source WebContents to launch the Web Intent "from".
136 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
137 WebContents* web_contents = chrome::GetActiveWebContents(browser());
138 ASSERT_TRUE(web_contents);
139
140 extensions::LaunchPlatformAppWithWebIntent(
141 browser()->profile(),
142 extension,
143 handler.intents_dispatcher(),
144 web_contents);
145
146 ASSERT_TRUE(handler.WaitUntilReply());
147 }
148
68 // Tests that platform apps cannot use certain disabled window properties, but 149 // Tests that platform apps cannot use certain disabled window properties, but
69 // can override them and then use them. 150 // can override them and then use them.
70 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisabledWindowProperties) { 151 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisabledWindowProperties) {
71 ASSERT_TRUE(RunPlatformAppTest("platform_apps/disabled_window_properties")) 152 ASSERT_TRUE(RunPlatformAppTest("platform_apps/disabled_window_properties"))
72 << message_; 153 << message_;
73 } 154 }
74 155
75 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, EmptyContextMenu) { 156 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, EmptyContextMenu) {
76 ExtensionTestMessageListener launched_listener("Launched", false); 157 ExtensionTestMessageListener launched_listener("Launched", false);
77 LoadAndLaunchPlatformApp("minimal"); 158 LoadAndLaunchPlatformApp("minimal");
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 // Tell javascript to open a third window. 566 // Tell javascript to open a third window.
486 page3_listener.Reply("continue"); 567 page3_listener.Reply("continue");
487 568
488 // Wait for javascript to verify that the third window got the restored size 569 // Wait for javascript to verify that the third window got the restored size
489 // and explicitly specified coordinates. 570 // and explicitly specified coordinates.
490 ASSERT_TRUE(done3_listener.WaitUntilSatisfied()); 571 ASSERT_TRUE(done3_listener.WaitUntilSatisfied());
491 } 572 }
492 #endif // defined(TOOLKIT_GTK) || defined(OS_MACOSX) 573 #endif // defined(TOOLKIT_GTK) || defined(OS_MACOSX)
493 574
494 } // namespace extensions 575 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/app_runtime/app_runtime_api.cc ('k') | chrome/browser/extensions/platform_app_launcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698