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

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

Issue 10915047: Links in platform apps should open in the system default browser. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 2 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 "chrome/browser/extensions/platform_app_browsertest_util.h" 5 #include "chrome/browser/extensions/platform_app_browsertest_util.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/stringprintf.h" 8 #include "base/stringprintf.h"
9 #include "chrome/browser/extensions/api/tabs/tabs.h" 9 #include "chrome/browser/extensions/api/tabs/tabs.h"
10 #include "chrome/browser/extensions/extension_function_test_utils.h" 10 #include "chrome/browser/extensions/extension_function_test_utils.h"
11 #include "chrome/browser/extensions/shell_window_registry.h" 11 #include "chrome/browser/extensions/shell_window_registry.h"
12 #include "chrome/browser/ui/browser.h" 12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/browser_list.h"
14 #include "chrome/browser/ui/browser_window.h"
13 #include "chrome/browser/ui/extensions/application_launch.h" 15 #include "chrome/browser/ui/extensions/application_launch.h"
14 #include "chrome/browser/ui/extensions/shell_window.h" 16 #include "chrome/browser/ui/extensions/shell_window.h"
15 #include "chrome/common/chrome_switches.h" 17 #include "chrome/common/chrome_switches.h"
16 #include "content/public/browser/notification_service.h" 18 #include "content/public/browser/notification_service.h"
17 #include "content/public/test/test_utils.h" 19 #include "content/public/test/test_utils.h"
18 20
19 using content::WebContents; 21 using content::WebContents;
20 22
21 namespace utils = extension_function_test_utils; 23 namespace utils = extension_function_test_utils;
22 24
23 namespace extensions { 25 namespace extensions {
24 26
27 MockExternalUrlController::MockExternalUrlController() {
28 }
29
30 MockExternalUrlController::~MockExternalUrlController() {
31 }
32
33 content::WebContents* MockExternalUrlController::OpenURLFromTab(
34 content::WebContents* source,
35 const content::OpenURLParams& params) {
36 // Delete useless web content first to
37 // avoid a potential leak in a render process host.
38 delete source;
39
40 // Force to open in a new tab.
41 WindowOpenDisposition disposition = params.disposition;
42 content::OpenURLParams new_tab_params = params;
43 new_tab_params.disposition =
44 disposition == NEW_BACKGROUND_TAB ? disposition : NEW_FOREGROUND_TAB;
45 for (BrowserList::const_iterator i = BrowserList::begin();
46 i != BrowserList::end(); ++i) {
47 if ((*i)->is_type_tabbed()) {
48 Browser* browser = *i;
49 content::WebContents* new_tab = browser->OpenURL(new_tab_params);
50 browser->window()->Show();
51 return new_tab;
52 }
53 }
54 return NULL;
55 }
56
57 PlatformAppBrowserTest::PlatformAppBrowserTest() {
58 }
59
60 PlatformAppBrowserTest::~PlatformAppBrowserTest() {
61 }
62
25 void PlatformAppBrowserTest::SetUpCommandLine(CommandLine* command_line) { 63 void PlatformAppBrowserTest::SetUpCommandLine(CommandLine* command_line) {
26 ExtensionBrowserTest::SetUpCommandLine(command_line); 64 ExtensionBrowserTest::SetUpCommandLine(command_line);
27 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); 65 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
28 } 66 }
29 67
68 void PlatformAppBrowserTest::SetUpOnMainThread() {
69 mock_external_url_controller_.reset(new MockExternalUrlController());
70 ShellWindow::SetExternalUrlControllerForTesting(
71 mock_external_url_controller_.get());
72 }
73
30 const Extension* PlatformAppBrowserTest::LoadAndLaunchPlatformApp( 74 const Extension* PlatformAppBrowserTest::LoadAndLaunchPlatformApp(
31 const char* name) { 75 const char* name) {
32 content::WindowedNotificationObserver app_loaded_observer( 76 content::WindowedNotificationObserver app_loaded_observer(
33 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, 77 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
34 content::NotificationService::AllSources()); 78 content::NotificationService::AllSources());
35 79
36 const Extension* extension = LoadExtension( 80 const Extension* extension = LoadExtension(
37 test_data_dir_.AppendASCII("platform_apps").AppendASCII(name)); 81 test_data_dir_.AppendASCII("platform_apps").AppendASCII(name));
38 EXPECT_TRUE(extension); 82 EXPECT_TRUE(extension);
39 83
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 185
142 void PlatformAppBrowserTest::CloseShellWindow(ShellWindow* window) { 186 void PlatformAppBrowserTest::CloseShellWindow(ShellWindow* window) {
143 content::WindowedNotificationObserver destroyed_observer( 187 content::WindowedNotificationObserver destroyed_observer(
144 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 188 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
145 content::NotificationService::AllSources()); 189 content::NotificationService::AllSources());
146 window->GetBaseWindow()->Close(); 190 window->GetBaseWindow()->Close();
147 destroyed_observer.Wait(); 191 destroyed_observer.Wait();
148 } 192 }
149 193
150 } // namespace extensions 194 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/platform_app_browsertest_util.h ('k') | chrome/browser/ui/extensions/shell_window.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698