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/app_window_registry.h"
10 #include "chrome/browser/apps/app_browsertest_util.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/ui/extensions/application_launch.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());
34 AppLaunchParams(profile(),
36 extensions::LAUNCH_CONTAINER_NONE,
38 app_loaded_observer.Wait();
42 const extensions::Extension* app_;
45 DISALLOW_COPY_AND_ASSIGN(NativeAppWindowCocoaBrowserTest);
50 // Test interaction of Hide/Show() with Hide/ShowWithApp().
51 IN_PROC_BROWSER_TEST_F(NativeAppWindowCocoaBrowserTest, HideShowWithApp) {
52 SetUpAppWithWindows(2);
53 apps::AppWindowRegistry::AppWindowList windows =
54 apps::AppWindowRegistry::Get(profile())->app_windows();
55 apps::NativeAppWindow* window = windows.front()->GetBaseWindow();
56 NSWindow* ns_window = window->GetNativeWindow();
57 apps::NativeAppWindow* other_window = windows.back()->GetBaseWindow();
58 NSWindow* other_ns_window = other_window->GetNativeWindow();
62 EXPECT_FALSE([ns_window isVisible]);
64 EXPECT_TRUE([ns_window isVisible]);
66 // Normal Hide/ShowWithApp.
67 window->HideWithApp();
68 EXPECT_FALSE([ns_window isVisible]);
69 window->ShowWithApp();
70 EXPECT_TRUE([ns_window isVisible]);
72 // HideWithApp, Hide, ShowWithApp does not show.
73 window->HideWithApp();
75 window->ShowWithApp();
76 EXPECT_FALSE([ns_window isVisible]);
78 // Hide, HideWithApp, ShowWithApp does not show.
79 window->HideWithApp();
80 window->ShowWithApp();
81 EXPECT_FALSE([ns_window isVisible]);
83 // Return to shown state.
85 EXPECT_TRUE([ns_window isVisible]);
87 // HideWithApp the other window.
88 EXPECT_TRUE([other_ns_window isVisible]);
89 other_window->HideWithApp();
90 EXPECT_FALSE([other_ns_window isVisible]);
92 // HideWithApp, Show shows all windows for this app.
93 window->HideWithApp();
94 EXPECT_FALSE([ns_window isVisible]);
96 EXPECT_TRUE([ns_window isVisible]);
97 EXPECT_TRUE([other_ns_window isVisible]);
99 // Hide the other window.
100 other_window->Hide();
101 EXPECT_FALSE([other_ns_window isVisible]);
103 // HideWithApp, ShowWithApp does not show the other window.
104 window->HideWithApp();
105 EXPECT_FALSE([ns_window isVisible]);
106 window->ShowWithApp();
107 EXPECT_TRUE([ns_window isVisible]);
108 EXPECT_FALSE([other_ns_window isVisible]);