| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2014 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 #include "chrome/browser/ui/cocoa/translate/translate_bubble_controller.h" |
| 6 |
| 7 #include "base/message_loop/message_loop.h" |
| 8 #import "chrome/browser/ui/browser.h" |
| 9 #include "chrome/browser/ui/browser_window.h" |
| 10 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 11 #import "chrome/browser/ui/cocoa/cocoa_profile_test.h" |
| 12 #import "chrome/browser/ui/cocoa/info_bubble_window.h" |
| 13 #import "chrome/browser/ui/cocoa/run_loop_testing.h" |
| 14 #include "chrome/common/url_constants.h" |
| 15 #include "content/public/browser/site_instance.h" |
| 16 |
| 17 @implementation BrowserWindowController (ForTesting) |
| 18 |
| 19 - (TranslateBubbleController*)translateBubbleController{ |
| 20 return translateBubbleController_; |
| 21 } |
| 22 |
| 23 @end |
| 24 |
| 25 class TranslateBubbleControllerTest : public CocoaProfileTest { |
| 26 public: |
| 27 virtual void SetUp() OVERRIDE { |
| 28 CocoaProfileTest::SetUp(); |
| 29 site_instance_ = content::SiteInstance::Create(profile()); |
| 30 } |
| 31 |
| 32 content::WebContents* AppendToTabStrip() { |
| 33 content::WebContents* web_contents = content::WebContents::Create( |
| 34 content::WebContents::CreateParams(profile(), site_instance_.get())); |
| 35 browser()->tab_strip_model()->AppendWebContents( |
| 36 web_contents, /*foreground=*/true); |
| 37 return web_contents; |
| 38 } |
| 39 |
| 40 private: |
| 41 scoped_refptr<content::SiteInstance> site_instance_; |
| 42 }; |
| 43 |
| 44 TEST_F(TranslateBubbleControllerTest, ShowAndClose) { |
| 45 NSWindow* nativeWindow = browser()->window()->GetNativeWindow(); |
| 46 BrowserWindowController* bwc = |
| 47 [BrowserWindowController browserWindowControllerForWindow:nativeWindow]; |
| 48 content::WebContents* webContents = AppendToTabStrip(); |
| 49 TranslateTabHelper::TranslateStep step = |
| 50 TranslateTabHelper::BEFORE_TRANSLATE; |
| 51 |
| 52 TranslateBubbleController* bubble = [bwc translateBubbleController]; |
| 53 EXPECT_FALSE(bubble); |
| 54 |
| 55 [bwc showTranslateBubbleForWebContents:webContents |
| 56 step:step |
| 57 errorType:TranslateErrors::NONE]; |
| 58 bubble = [bwc translateBubbleController]; |
| 59 EXPECT_TRUE(bubble); |
| 60 InfoBubbleWindow* window = (InfoBubbleWindow*)[bubble window]; |
| 61 [window setAllowedAnimations:info_bubble::kAnimateNone]; |
| 62 |
| 63 [bubble close]; |
| 64 chrome::testing::NSRunLoopRunAllPending(); |
| 65 bubble = [bwc translateBubbleController]; |
| 66 EXPECT_FALSE(bubble); |
| 67 } |
| OLD | NEW |