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