native_app_window_cocoa_browsertest.mm revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
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/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" 15 16using extensions::PlatformAppBrowserTest; 17 18namespace { 19 20class 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( 34 AppLaunchParams(profile(), 35 app_, 36 extensions::LAUNCH_CONTAINER_NONE, 37 NEW_WINDOW)); 38 app_loaded_observer.Wait(); 39 } 40 } 41 42 const extensions::Extension* app_; 43 44 private: 45 DISALLOW_COPY_AND_ASSIGN(NativeAppWindowCocoaBrowserTest); 46}; 47 48} // namespace 49 50// Test interaction of Hide/Show() with Hide/ShowWithApp(). 51IN_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(); 59 60 // Normal Hide/Show. 61 window->Hide(); 62 EXPECT_FALSE([ns_window isVisible]); 63 window->Show(); 64 EXPECT_TRUE([ns_window isVisible]); 65 66 // Normal Hide/ShowWithApp. 67 window->HideWithApp(); 68 EXPECT_FALSE([ns_window isVisible]); 69 window->ShowWithApp(); 70 EXPECT_TRUE([ns_window isVisible]); 71 72 // HideWithApp, Hide, ShowWithApp does not show. 73 window->HideWithApp(); 74 window->Hide(); 75 window->ShowWithApp(); 76 EXPECT_FALSE([ns_window isVisible]); 77 78 // Hide, HideWithApp, ShowWithApp does not show. 79 window->HideWithApp(); 80 window->ShowWithApp(); 81 EXPECT_FALSE([ns_window isVisible]); 82 83 // Return to shown state. 84 window->Show(); 85 EXPECT_TRUE([ns_window isVisible]); 86 87 // HideWithApp the other window. 88 EXPECT_TRUE([other_ns_window isVisible]); 89 other_window->HideWithApp(); 90 EXPECT_FALSE([other_ns_window isVisible]); 91 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]); 98 99 // Hide the other window. 100 other_window->Hide(); 101 EXPECT_FALSE([other_ns_window isVisible]); 102 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]); 109} 110