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

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

Powered by Google App Engine
This is Rietveld 408576698