| 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/run_loop_testing.h" |
| 13 #include "chrome/common/url_constants.h" |
| 14 #include "content/public/browser/site_instance.h" |
| 15 |
| 16 @implementation BrowserWindowController (ForTesting) |
| 17 |
| 18 - (TranslateBubbleController*)translateBubbleController{ |
| 19 return translateBubbleController_; |
| 20 } |
| 21 |
| 22 @end |
| 23 |
| 24 class TranslateBubbleControllerTest : public CocoaProfileTest { |
| 25 public: |
| 26 virtual void SetUp() OVERRIDE { |
| 27 CocoaProfileTest::SetUp(); |
| 28 site_instance_ = content::SiteInstance::Create(profile()); |
| 29 } |
| 30 |
| 31 content::WebContents* AppendToTabStrip() { |
| 32 content::WebContents* web_contents = content::WebContents::Create( |
| 33 content::WebContents::CreateParams(profile(), site_instance_.get())); |
| 34 browser()->tab_strip_model()->AppendWebContents( |
| 35 web_contents, /*foreground=*/true); |
| 36 return web_contents; |
| 37 } |
| 38 |
| 39 private: |
| 40 scoped_refptr<content::SiteInstance> site_instance_; |
| 41 }; |
| 42 |
| 43 TEST_F(TranslateBubbleControllerTest, ShowAndClose) { |
| 44 NSWindow* nativeWindow = browser()->window()->GetNativeWindow(); |
| 45 BrowserWindowController* bwc = |
| 46 [BrowserWindowController browserWindowControllerForWindow:nativeWindow]; |
| 47 content::WebContents* webContents = AppendToTabStrip(); |
| 48 TranslateTabHelper::TranslateStep step = |
| 49 TranslateTabHelper::BEFORE_TRANSLATE; |
| 50 |
| 51 TranslateBubbleController* bubble = [bwc translateBubbleController]; |
| 52 EXPECT_FALSE(bubble); |
| 53 |
| 54 [bwc showTranslateBubbleForWebContents:webContents |
| 55 step:step |
| 56 errorType:TranslateErrors::NONE]; |
| 57 bubble = [bwc translateBubbleController]; |
| 58 EXPECT_TRUE(bubble); |
| 59 |
| 60 [bubble close]; |
| 61 // TODO(hajimehoshi,groby) NSRunLoopRunAllPending should work here but it |
| 62 // doesn't for some reason (crbug/347855). |
| 63 base::MessageLoopForUI::current()->RunUntilIdle(); |
| 64 bubble = [bwc translateBubbleController]; |
| 65 EXPECT_FALSE(bubble); |
| 66 } |
| OLD | NEW |