OLD | NEW |
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 #import <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/memory/scoped_nsobject.h" | 8 #include "base/memory/scoped_nsobject.h" |
9 #include "chrome/app/chrome_command_ids.h" | 9 #include "chrome/app/chrome_command_ids.h" |
10 #import "chrome/browser/app_controller_mac.h" | 10 #import "chrome/browser/app_controller_mac.h" |
11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
12 #include "chrome/browser/ui/browser_list.h" | 12 #include "chrome/browser/ui/browser_list.h" |
| 13 #include "chrome/browser/ui/browser_list_impl.h" |
| 14 #include "chrome/browser/ui/host_desktop.h" |
13 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 15 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
14 #import "chrome/common/chrome_switches.h" | 16 #import "chrome/common/chrome_switches.h" |
15 #include "chrome/test/base/in_process_browser_test.h" | 17 #include "chrome/test/base/in_process_browser_test.h" |
16 #include "chrome/test/base/ui_test_utils.h" | 18 #include "chrome/test/base/ui_test_utils.h" |
17 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
18 | 20 |
19 namespace { | 21 namespace { |
20 | 22 |
21 class AppControllerPlatformAppBrowserTest : public InProcessBrowserTest { | 23 class AppControllerPlatformAppBrowserTest : public InProcessBrowserTest { |
22 protected: | 24 protected: |
23 AppControllerPlatformAppBrowserTest() {} | 25 AppControllerPlatformAppBrowserTest() |
| 26 : native_browser_list(chrome::BrowserListImpl::GetInstance( |
| 27 chrome::HOST_DESKTOP_TYPE_NATIVE)) { |
| 28 } |
24 | 29 |
25 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 30 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
26 command_line->AppendSwitchASCII(switches::kAppId, | 31 command_line->AppendSwitchASCII(switches::kAppId, |
27 "1234"); | 32 "1234"); |
28 } | 33 } |
| 34 |
| 35 private: |
| 36 // Mac only has the native desktop. |
| 37 const chrome::BrowserListImpl* native_browser_list; |
29 }; | 38 }; |
30 | 39 |
31 // Test that if only a platform app window is open and no browser windows are | 40 // Test that if only a platform app window is open and no browser windows are |
32 // open then a reopen event does nothing. | 41 // open then a reopen event does nothing. |
33 IN_PROC_BROWSER_TEST_F(AppControllerPlatformAppBrowserTest, | 42 IN_PROC_BROWSER_TEST_F(AppControllerPlatformAppBrowserTest, |
34 PlatformAppReopenWithWindows) { | 43 PlatformAppReopenWithWindows) { |
35 scoped_nsobject<AppController> ac([[AppController alloc] init]); | 44 scoped_nsobject<AppController> ac([[AppController alloc] init]); |
36 NSUInteger old_window_count = [[NSApp windows] count]; | 45 NSUInteger old_window_count = [[NSApp windows] count]; |
37 EXPECT_EQ(1u, BrowserList::size()); | 46 EXPECT_EQ(1u, native_browser_list->size()); |
38 BOOL result = [ac applicationShouldHandleReopen:NSApp hasVisibleWindows:YES]; | 47 BOOL result = [ac applicationShouldHandleReopen:NSApp hasVisibleWindows:YES]; |
39 | 48 |
40 EXPECT_TRUE(result); | 49 EXPECT_TRUE(result); |
41 EXPECT_EQ(old_window_count, [[NSApp windows] count]); | 50 EXPECT_EQ(old_window_count, [[NSApp windows] count]); |
42 EXPECT_EQ(1u, BrowserList::size()); | 51 EXPECT_EQ(1u, native_browser_list->size()); |
43 } | 52 } |
44 | 53 |
45 class AppControllerWebAppBrowserTest : public InProcessBrowserTest { | 54 class AppControllerWebAppBrowserTest : public InProcessBrowserTest { |
46 protected: | 55 protected: |
47 AppControllerWebAppBrowserTest() {} | 56 AppControllerWebAppBrowserTest() {} |
48 | 57 |
49 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 58 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
50 command_line->AppendSwitchASCII(switches::kApp, GetAppURL()); | 59 command_line->AppendSwitchASCII(switches::kApp, GetAppURL()); |
51 } | 60 } |
52 | 61 |
53 std::string GetAppURL() const { | 62 std::string GetAppURL() const { |
54 return "http://example.com/"; | 63 return "http://example.com/"; |
55 } | 64 } |
56 }; | 65 }; |
57 | 66 |
58 // Test that in web app mode a reopen event opens the app URL. | 67 // Test that in web app mode a reopen event opens the app URL. |
59 IN_PROC_BROWSER_TEST_F(AppControllerWebAppBrowserTest, | 68 IN_PROC_BROWSER_TEST_F(AppControllerWebAppBrowserTest, |
60 WebAppReopenWithNoWindows) { | 69 WebAppReopenWithNoWindows) { |
61 scoped_nsobject<AppController> ac([[AppController alloc] init]); | 70 scoped_nsobject<AppController> ac([[AppController alloc] init]); |
62 EXPECT_EQ(1u, BrowserList::size()); | 71 EXPECT_EQ(1u, native_browser_list->size()); |
63 BOOL result = [ac applicationShouldHandleReopen:NSApp hasVisibleWindows:NO]; | 72 BOOL result = [ac applicationShouldHandleReopen:NSApp hasVisibleWindows:NO]; |
64 | 73 |
65 EXPECT_FALSE(result); | 74 EXPECT_FALSE(result); |
66 EXPECT_EQ(2u, BrowserList::size()); | 75 EXPECT_EQ(2u, native_browser_list->size()); |
67 | 76 |
68 Browser* browser = *(BrowserList::begin()); | 77 Browser* browser = native_browser_list->get(0); |
69 GURL current_url = | 78 GURL current_url = |
70 browser->tab_strip_model()->GetActiveWebContents()->GetURL(); | 79 browser->tab_strip_model()->GetActiveWebContents()->GetURL(); |
71 EXPECT_EQ(GetAppURL(), current_url.spec()); | 80 EXPECT_EQ(GetAppURL(), current_url.spec()); |
72 } | 81 } |
73 | 82 |
74 } // namespace | 83 } // namespace |
OLD | NEW |