1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "chrome/browser/ui/cocoa/apps/native_app_window_cocoa.h"
#import <Cocoa/Cocoa.h>
#include "apps/app_window_registry.h"
#include "chrome/browser/apps/app_browsertest_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/extensions/application_launch.h"
#include "content/public/browser/notification_service.h"
#include "content/public/test/test_utils.h"
using extensions::PlatformAppBrowserTest;
namespace {
class NativeAppWindowCocoaBrowserTest : public PlatformAppBrowserTest {
protected:
NativeAppWindowCocoaBrowserTest() {}
void SetUpAppWithWindows(int num_windows) {
app_ = InstallExtension(
test_data_dir_.AppendASCII("platform_apps").AppendASCII("minimal"), 1);
EXPECT_TRUE(app_);
for (int i = 0; i < num_windows; ++i) {
content::WindowedNotificationObserver app_loaded_observer(
content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
content::NotificationService::AllSources());
OpenApplication(
AppLaunchParams(profile(),
app_,
extensions::LAUNCH_CONTAINER_NONE,
NEW_WINDOW));
app_loaded_observer.Wait();
}
}
const extensions::Extension* app_;
private:
DISALLOW_COPY_AND_ASSIGN(NativeAppWindowCocoaBrowserTest);
};
} // namespace
// Test interaction of Hide/Show() with Hide/ShowWithApp().
IN_PROC_BROWSER_TEST_F(NativeAppWindowCocoaBrowserTest, HideShowWithApp) {
SetUpAppWithWindows(2);
apps::AppWindowRegistry::AppWindowList windows =
apps::AppWindowRegistry::Get(profile())->app_windows();
apps::NativeAppWindow* window = windows.front()->GetBaseWindow();
NSWindow* ns_window = window->GetNativeWindow();
apps::NativeAppWindow* other_window = windows.back()->GetBaseWindow();
NSWindow* other_ns_window = other_window->GetNativeWindow();
// Normal Hide/Show.
window->Hide();
EXPECT_FALSE([ns_window isVisible]);
window->Show();
EXPECT_TRUE([ns_window isVisible]);
// Normal Hide/ShowWithApp.
window->HideWithApp();
EXPECT_FALSE([ns_window isVisible]);
window->ShowWithApp();
EXPECT_TRUE([ns_window isVisible]);
// HideWithApp, Hide, ShowWithApp does not show.
window->HideWithApp();
window->Hide();
window->ShowWithApp();
EXPECT_FALSE([ns_window isVisible]);
// Hide, HideWithApp, ShowWithApp does not show.
window->HideWithApp();
window->ShowWithApp();
EXPECT_FALSE([ns_window isVisible]);
// Return to shown state.
window->Show();
EXPECT_TRUE([ns_window isVisible]);
// HideWithApp the other window.
EXPECT_TRUE([other_ns_window isVisible]);
other_window->HideWithApp();
EXPECT_FALSE([other_ns_window isVisible]);
// HideWithApp, Show shows all windows for this app.
window->HideWithApp();
EXPECT_FALSE([ns_window isVisible]);
window->Show();
EXPECT_TRUE([ns_window isVisible]);
EXPECT_TRUE([other_ns_window isVisible]);
// Hide the other window.
other_window->Hide();
EXPECT_FALSE([other_ns_window isVisible]);
// HideWithApp, ShowWithApp does not show the other window.
window->HideWithApp();
EXPECT_FALSE([ns_window isVisible]);
window->ShowWithApp();
EXPECT_TRUE([ns_window isVisible]);
EXPECT_FALSE([other_ns_window isVisible]);
}
|