NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / apps / native_app_window_cocoa_browsertest.mm
blob197680667bdea8348b77082c9b71668968a77908
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;
18 namespace {
20 class NativeAppWindowCocoaBrowserTest : public PlatformAppBrowserTest {
21  protected:
22   NativeAppWindowCocoaBrowserTest() {}
24   void SetUpAppWithWindows(int num_windows) {
25     app_ = InstallExtension(
26         test_data_dir_.AppendASCII("platform_apps").AppendASCII("minimal"), 1);
27     EXPECT_TRUE(app_);
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(
34           AppLaunchParams(profile(),
35                           app_,
36                           extensions::LAUNCH_CONTAINER_NONE,
37                           NEW_WINDOW));
38       app_loaded_observer.Wait();
39     }
40   }
42   const extensions::Extension* app_;
44  private:
45   DISALLOW_COPY_AND_ASSIGN(NativeAppWindowCocoaBrowserTest);
48 }  // namespace
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();
60   // Normal Hide/Show.
61   window->Hide();
62   EXPECT_FALSE([ns_window isVisible]);
63   window->Show();
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();
74   window->Hide();
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.
84   window->Show();
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]);
95   window->Show();
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]);