Upstream version 5.34.92.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / cocoa / apps / native_app_window_cocoa_browsertest.mm
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.
4
5 #import "chrome/browser/ui/cocoa/apps/native_app_window_cocoa.h"
6
7 #import <Cocoa/Cocoa.h>
8
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"
15
16 using extensions::PlatformAppBrowserTest;
17
18 namespace {
19
20 class NativeAppWindowCocoaBrowserTest : public PlatformAppBrowserTest {
21  protected:
22   NativeAppWindowCocoaBrowserTest() {}
23
24   void SetUpAppWithWindows(int num_windows) {
25     app_ = InstallExtension(
26         test_data_dir_.AppendASCII("platform_apps").AppendASCII("minimal"), 1);
27     EXPECT_TRUE(app_);
28
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();
36     }
37   }
38
39   const extensions::Extension* app_;
40
41  private:
42   DISALLOW_COPY_AND_ASSIGN(NativeAppWindowCocoaBrowserTest);
43 };
44
45 }  // namespace
46
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();
56
57   // Normal Hide/Show.
58   window->Hide();
59   EXPECT_FALSE([ns_window isVisible]);
60   window->Show();
61   EXPECT_TRUE([ns_window isVisible]);
62
63   // Normal Hide/ShowWithApp.
64   window->HideWithApp();
65   EXPECT_FALSE([ns_window isVisible]);
66   window->ShowWithApp();
67   EXPECT_TRUE([ns_window isVisible]);
68
69   // HideWithApp, Hide, ShowWithApp does not show.
70   window->HideWithApp();
71   window->Hide();
72   window->ShowWithApp();
73   EXPECT_FALSE([ns_window isVisible]);
74
75   // Hide, HideWithApp, ShowWithApp does not show.
76   window->HideWithApp();
77   window->ShowWithApp();
78   EXPECT_FALSE([ns_window isVisible]);
79
80   // Return to shown state.
81   window->Show();
82   EXPECT_TRUE([ns_window isVisible]);
83
84   // HideWithApp the other window.
85   EXPECT_TRUE([other_ns_window isVisible]);
86   other_window->HideWithApp();
87   EXPECT_FALSE([other_ns_window isVisible]);
88
89   // HideWithApp, Show shows all windows for this app.
90   window->HideWithApp();
91   EXPECT_FALSE([ns_window isVisible]);
92   window->Show();
93   EXPECT_TRUE([ns_window isVisible]);
94   EXPECT_TRUE([other_ns_window isVisible]);
95
96   // Hide the other window.
97   other_window->Hide();
98   EXPECT_FALSE([other_ns_window isVisible]);
99
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]);
106 }