1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #import "chrome/browser/ui/cocoa/apps/native_app_window_cocoa.h"
7 #import <Cocoa/Cocoa.h>
9 #include "apps/shell_window_registry.h"
10 #include "chrome/browser/apps/app_browsertest_util.h"
11 #include "chrome/browser/ui/extensions/application_launch.h"
12 #include "content/public/browser/notification_service.h"
13 #include "content/public/test/test_utils.h"
15 using extensions::PlatformAppBrowserTest;
19 class NativeAppWindowCocoaBrowserTest : public PlatformAppBrowserTest {
21 NativeAppWindowCocoaBrowserTest() {}
23 void SetUpAppWithWindows(int num_windows) {
24 app_ = InstallExtension(
25 test_data_dir_.AppendASCII("platform_apps").AppendASCII("minimal"), 1);
28 for (int i = 0; i < num_windows; ++i) {
29 content::WindowedNotificationObserver app_loaded_observer(
30 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
31 content::NotificationService::AllSources());
32 chrome::OpenApplication(chrome::AppLaunchParams(
33 profile(), app_, extension_misc::LAUNCH_NONE, NEW_WINDOW));
34 app_loaded_observer.Wait();
38 const extensions::Extension* app_;
41 DISALLOW_COPY_AND_ASSIGN(NativeAppWindowCocoaBrowserTest);
46 // Test interaction of Hide/Show() with Hide/ShowWithApp().
47 IN_PROC_BROWSER_TEST_F(NativeAppWindowCocoaBrowserTest, HideShowWithApp) {
48 SetUpAppWithWindows(2);
49 apps::ShellWindowRegistry::ShellWindowList windows =
50 apps::ShellWindowRegistry::Get(profile())->shell_windows();
51 apps::NativeAppWindow* window = windows.front()->GetBaseWindow();
52 NSWindow* ns_window = window->GetNativeWindow();
53 apps::NativeAppWindow* other_window = windows.back()->GetBaseWindow();
54 NSWindow* other_ns_window = other_window->GetNativeWindow();
58 EXPECT_FALSE([ns_window isVisible]);
60 EXPECT_TRUE([ns_window isVisible]);
62 // Normal Hide/ShowWithApp.
63 window->HideWithApp();
64 EXPECT_FALSE([ns_window isVisible]);
65 window->ShowWithApp();
66 EXPECT_TRUE([ns_window isVisible]);
68 // HideWithApp, Hide, ShowWithApp does not show.
69 window->HideWithApp();
71 window->ShowWithApp();
72 EXPECT_FALSE([ns_window isVisible]);
74 // Hide, HideWithApp, ShowWithApp does not show.
75 window->HideWithApp();
76 window->ShowWithApp();
77 EXPECT_FALSE([ns_window isVisible]);
79 // Return to shown state.
81 EXPECT_TRUE([ns_window isVisible]);
83 // HideWithApp the other window.
84 EXPECT_TRUE([other_ns_window isVisible]);
85 other_window->HideWithApp();
86 EXPECT_FALSE([other_ns_window isVisible]);
88 // HideWithApp, Show shows all windows for this app.
89 window->HideWithApp();
90 EXPECT_FALSE([ns_window isVisible]);
92 EXPECT_TRUE([ns_window isVisible]);
93 EXPECT_TRUE([other_ns_window isVisible]);
95 // Hide the other window.
97 EXPECT_FALSE([other_ns_window isVisible]);
99 // HideWithApp, ShowWithApp does not show the other window.
100 window->HideWithApp();
101 EXPECT_FALSE([ns_window isVisible]);
102 window->ShowWithApp();
103 EXPECT_TRUE([ns_window isVisible]);
104 EXPECT_FALSE([other_ns_window isVisible]);