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

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

Issue 12225076: Delete most web intents code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 10 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
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/bind.h"
6 #include "base/test/test_timeouts.h" 6 #include "base/test/test_timeouts.h"
7 #include "base/threading/platform_thread.h" 7 #include "base/threading/platform_thread.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/app/chrome_command_ids.h" 9 #include "chrome/app/chrome_command_ids.h"
10 #include "chrome/browser/automation/automation_util.h" 10 #include "chrome/browser/automation/automation_util.h"
(...skipping 16 matching lines...) Expand all
27 #include "chrome/browser/ui/extensions/shell_window.h" 27 #include "chrome/browser/ui/extensions/shell_window.h"
28 #include "chrome/browser/ui/tabs/tab_strip_model.h" 28 #include "chrome/browser/ui/tabs/tab_strip_model.h"
29 #include "chrome/browser/ui/web_contents_modal_dialog_manager.h" 29 #include "chrome/browser/ui/web_contents_modal_dialog_manager.h"
30 #include "chrome/common/chrome_notification_types.h" 30 #include "chrome/common/chrome_notification_types.h"
31 #include "chrome/common/url_constants.h" 31 #include "chrome/common/url_constants.h"
32 #include "chrome/test/base/ui_test_utils.h" 32 #include "chrome/test/base/ui_test_utils.h"
33 #include "content/public/browser/devtools_agent_host.h" 33 #include "content/public/browser/devtools_agent_host.h"
34 #include "content/public/browser/render_process_host.h" 34 #include "content/public/browser/render_process_host.h"
35 #include "content/public/browser/render_widget_host_view.h" 35 #include "content/public/browser/render_widget_host_view.h"
36 #include "content/public/browser/web_contents_view.h" 36 #include "content/public/browser/web_contents_view.h"
37 #include "content/public/browser/web_intents_dispatcher.h"
38 #include "content/public/test/test_utils.h" 37 #include "content/public/test/test_utils.h"
39 #include "googleurl/src/gurl.h" 38 #include "googleurl/src/gurl.h"
40 #include "webkit/glue/web_intent_data.h"
41 39
42 using content::WebContents; 40 using content::WebContents;
43 41
44 namespace extensions { 42 namespace extensions {
45 43
46 namespace { 44 namespace {
47 45
48 // Non-abstract RenderViewContextMenu class. 46 // Non-abstract RenderViewContextMenu class.
49 class PlatformAppContextMenu : public RenderViewContextMenu { 47 class PlatformAppContextMenu : public RenderViewContextMenu {
50 public: 48 public:
51 PlatformAppContextMenu(WebContents* web_contents, 49 PlatformAppContextMenu(WebContents* web_contents,
52 const content::ContextMenuParams& params) 50 const content::ContextMenuParams& params)
53 : RenderViewContextMenu(web_contents, params) {} 51 : RenderViewContextMenu(web_contents, params) {}
54 52
55 bool HasCommandWithId(int command_id) { 53 bool HasCommandWithId(int command_id) {
56 return menu_model_.GetIndexOfCommandId(command_id) != -1; 54 return menu_model_.GetIndexOfCommandId(command_id) != -1;
57 } 55 }
58 56
59 protected: 57 protected:
60 // RenderViewContextMenu implementation. 58 // RenderViewContextMenu implementation.
61 virtual bool GetAcceleratorForCommandId( 59 virtual bool GetAcceleratorForCommandId(
62 int command_id, 60 int command_id,
63 ui::Accelerator* accelerator) OVERRIDE { 61 ui::Accelerator* accelerator) OVERRIDE {
64 return false; 62 return false;
65 } 63 }
66 virtual void PlatformInit() OVERRIDE {} 64 virtual void PlatformInit() OVERRIDE {}
67 virtual void PlatformCancel() OVERRIDE {} 65 virtual void PlatformCancel() OVERRIDE {}
68 }; 66 };
69 67
70 #if defined(ENABLE_WEB_INTENTS)
71 // State holder for the LaunchReply test. This provides an WebIntentsDispatcher
72 // that will, when used to launch a Web Intent, will return its reply via this
73 // class. The result may then be waited on via WaitUntilReply().
74 class LaunchReplyHandler {
75 public:
76 explicit LaunchReplyHandler(webkit_glue::WebIntentData& data)
77 : data_(data),
78 replied_(false),
79 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
80 intents_dispatcher_ = content::WebIntentsDispatcher::Create(data);
81 intents_dispatcher_->RegisterReplyNotification(base::Bind(
82 &LaunchReplyHandler::OnReply, weak_ptr_factory_.GetWeakPtr()));
83 }
84
85 content::WebIntentsDispatcher* intents_dispatcher() {
86 return intents_dispatcher_;
87 }
88
89 // Waits until a reply to this Web Intent is provided via the
90 // WebIntentsDispatcher.
91 bool WaitUntilReply() {
92 if (replied_)
93 return true;
94 waiting_ = true;
95 content::RunMessageLoop();
96 waiting_ = false;
97 return replied_;
98 }
99
100 private:
101 void OnReply(webkit_glue::WebIntentReplyType reply) {
102 // Note that the ReplyNotification registered on WebIntentsDispatcher does
103 // not include the result data: this is reserved for the source page (which
104 // we don't care about).
105 replied_ = true;
106 if (waiting_)
107 MessageLoopForUI::current()->Quit();
108 }
109
110 webkit_glue::WebIntentData data_;
111 bool replied_;
112 bool waiting_;
113 content::WebIntentsDispatcher* intents_dispatcher_;
114 base::WeakPtrFactory<LaunchReplyHandler> weak_ptr_factory_;
115 };
116 #endif
117
118 // This class keeps track of tabs as they are added to the browser. It will be 68 // This class keeps track of tabs as they are added to the browser. It will be
119 // "done" (i.e. won't block on Wait()) once |observations| tabs have been added. 69 // "done" (i.e. won't block on Wait()) once |observations| tabs have been added.
120 class TabsAddedNotificationObserver 70 class TabsAddedNotificationObserver
121 : public content::WindowedNotificationObserver { 71 : public content::WindowedNotificationObserver {
122 public: 72 public:
123 explicit TabsAddedNotificationObserver(size_t observations) 73 explicit TabsAddedNotificationObserver(size_t observations)
124 : content::WindowedNotificationObserver( 74 : content::WindowedNotificationObserver(
125 chrome::NOTIFICATION_TAB_ADDED, 75 chrome::NOTIFICATION_TAB_ADDED,
126 content::NotificationService::AllSources()), 76 content::NotificationService::AllSources()),
127 observations_(observations) { 77 observations_(observations) {
(...skipping 28 matching lines...) Expand all
156 const Extension* extension = LoadAndLaunchPlatformApp("minimal"); 106 const Extension* extension = LoadAndLaunchPlatformApp("minimal");
157 ShellWindow* window = CreateShellWindow(extension); 107 ShellWindow* window = CreateShellWindow(extension);
158 CloseShellWindow(window); 108 CloseShellWindow(window);
159 } 109 }
160 110
161 // Tests that platform apps received the "launch" event when launched. 111 // Tests that platform apps received the "launch" event when launched.
162 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, OnLaunchedEvent) { 112 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, OnLaunchedEvent) {
163 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch")) << message_; 113 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch")) << message_;
164 } 114 }
165 115
166 #if defined(ENABLE_WEB_INTENTS)
167 // Tests that platform apps can reply to "launch" events that contain a Web
168 // Intent. This test does not test the mechanics of invoking a Web Intent
169 // from a source page, and short-circuits to LaunchPlatformAppWithWebIntent.
170 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchReply) {
171 base::FilePath path =
172 test_data_dir_.AppendASCII("platform_apps/launch_reply");
173 const extensions::Extension* extension = LoadExtension(path);
174 ASSERT_TRUE(extension) << "Failed to load extension.";
175
176 webkit_glue::WebIntentData data(
177 UTF8ToUTF16("http://webintents.org/view"),
178 UTF8ToUTF16("text/plain"),
179 UTF8ToUTF16("irrelevant unserialized string data"));
180 LaunchReplyHandler handler(data);
181
182 // Navigate to a boring page: we don't care what it is, but we require some
183 // source WebContents to launch the Web Intent "from".
184 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
185 WebContents* web_contents =
186 browser()->tab_strip_model()->GetActiveWebContents();
187 ASSERT_TRUE(web_contents);
188
189 extensions::LaunchPlatformAppWithWebIntent(
190 browser()->profile(),
191 extension,
192 handler.intents_dispatcher(),
193 web_contents);
194
195 ASSERT_TRUE(handler.WaitUntilReply());
196 }
197 #endif
198
199 // Tests that platform apps cannot use certain disabled window properties, but 116 // Tests that platform apps cannot use certain disabled window properties, but
200 // can override them and then use them. 117 // can override them and then use them.
201 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisabledWindowProperties) { 118 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisabledWindowProperties) {
202 ASSERT_TRUE(RunPlatformAppTest("platform_apps/disabled_window_properties")) 119 ASSERT_TRUE(RunPlatformAppTest("platform_apps/disabled_window_properties"))
203 << message_; 120 << message_;
204 } 121 }
205 122
206 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, EmptyContextMenu) { 123 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, EmptyContextMenu) {
207 ExtensionTestMessageListener launched_listener("Launched", false); 124 ExtensionTestMessageListener launched_listener("Launched", false);
208 LoadAndLaunchPlatformApp("minimal"); 125 LoadAndLaunchPlatformApp("minimal");
(...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after
928 #define MAYBE_WebContentsHasFocus WebContentsHasFocus 845 #define MAYBE_WebContentsHasFocus WebContentsHasFocus
929 #endif 846 #endif
930 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, MAYBE_WebContentsHasFocus) { 847 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, MAYBE_WebContentsHasFocus) {
931 const Extension* extension = LoadAndLaunchPlatformApp("minimal"); 848 const Extension* extension = LoadAndLaunchPlatformApp("minimal");
932 ShellWindow* window = CreateShellWindow(extension); 849 ShellWindow* window = CreateShellWindow(extension);
933 EXPECT_TRUE(window->web_contents()->GetRenderWidgetHostView()->HasFocus()); 850 EXPECT_TRUE(window->web_contents()->GetRenderWidgetHostView()->HasFocus());
934 CloseShellWindow(window); 851 CloseShellWindow(window);
935 } 852 }
936 853
937 } // namespace extensions 854 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698