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