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 "chrome/browser/profiles/profile.h"
13 #include "content/public/browser/notification_service.h"
14 #include "content/public/test/test_utils.h"
16 using extensions::PlatformAppBrowserTest;
20 class NativeAppWindowCocoaBrowserTest : public PlatformAppBrowserTest {
22 NativeAppWindowCocoaBrowserTest() {}
24 void SetUpAppWithWindows(int num_windows) {
25 app_ = InstallExtension(
26 test_data_dir_.AppendASCII("platform_apps").AppendASCII("minimal"), 1);
29 for (int i = 0; i < num_windows; ++i) {
30 content::WindowedNotificationObserver app_loaded_observer(
31 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
32 content::NotificationService::AllSources());
33 OpenApplication(AppLaunchParams(
34 profile(), app_, extensions::LAUNCH_CONTAINER_NONE, NEW_WINDOW));
35 app_loaded_observer.Wait();
39 const extensions::Extension* app_;
42 DISALLOW_COPY_AND_ASSIGN(NativeAppWindowCocoaBrowserTest);
47 // Test interaction of Hide/Show() with Hide/ShowWithApp().
48 IN_PROC_BROWSER_TEST_F(NativeAppWindowCocoaBrowserTest, HideShowWithApp) {
49 SetUpAppWithWindows(2);
50 apps::ShellWindowRegistry::ShellWindowList windows =
51 apps::ShellWindowRegistry::Get(profile())->shell_windows();
52 apps::NativeAppWindow* window = windows.front()->GetBaseWindow();
53 NSWindow* ns_window = window->GetNativeWindow();
54 apps::NativeAppWindow* other_window = windows.back()->GetBaseWindow();
55 NSWindow* other_ns_window = other_window->GetNativeWindow();
59 EXPECT_FALSE([ns_window isVisible]);
61 EXPECT_TRUE([ns_window isVisible]);
63 // Normal Hide/ShowWithApp.
64 window->HideWithApp();
65 EXPECT_FALSE([ns_window isVisible]);
66 window->ShowWithApp();
67 EXPECT_TRUE([ns_window isVisible]);
69 // HideWithApp, Hide, ShowWithApp does not show.
70 window->HideWithApp();
72 window->ShowWithApp();
73 EXPECT_FALSE([ns_window isVisible]);
75 // Hide, HideWithApp, ShowWithApp does not show.
76 window->HideWithApp();
77 window->ShowWithApp();
78 EXPECT_FALSE([ns_window isVisible]);
80 // Return to shown state.
82 EXPECT_TRUE([ns_window isVisible]);
84 // HideWithApp the other window.
85 EXPECT_TRUE([other_ns_window isVisible]);
86 other_window->HideWithApp();
87 EXPECT_FALSE([other_ns_window isVisible]);
89 // HideWithApp, Show shows all windows for this app.
90 window->HideWithApp();
91 EXPECT_FALSE([ns_window isVisible]);
93 EXPECT_TRUE([ns_window isVisible]);
94 EXPECT_TRUE([other_ns_window isVisible]);
96 // Hide the other window.
98 EXPECT_FALSE([other_ns_window isVisible]);
100 // HideWithApp, ShowWithApp does not show the other window.
101 window->HideWithApp();
102 EXPECT_FALSE([ns_window isVisible]);
103 window->ShowWithApp();
104 EXPECT_TRUE([ns_window isVisible]);
105 EXPECT_FALSE([other_ns_window isVisible]);