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.
5 #include "chrome/browser/ui/cocoa/translate/translate_bubble_controller.h"
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 #include "chrome/browser/ui/cocoa/run_loop_testing.h"
14 #include "chrome/common/url_constants.h"
15 #include "content/public/browser/site_instance.h"
17 @implementation BrowserWindowController (ForTesting)
19 - (TranslateBubbleController*)translateBubbleController{
20 return translateBubbleController_;
25 class TranslateBubbleControllerTest : public CocoaProfileTest {
27 void SetUp() override {
28 CocoaProfileTest::SetUp();
29 site_instance_ = content::SiteInstance::Create(profile());
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);
41 scoped_refptr<content::SiteInstance> site_instance_;
44 TEST_F(TranslateBubbleControllerTest, ShowAndClose) {
45 NSWindow* nativeWindow = browser()->window()->GetNativeWindow();
46 BrowserWindowController* bwc =
47 [BrowserWindowController browserWindowControllerForWindow:nativeWindow];
48 content::WebContents* webContents = AppendToTabStrip();
49 translate::TranslateStep step = translate::TRANSLATE_STEP_BEFORE_TRANSLATE;
51 TranslateBubbleController* bubble = [bwc translateBubbleController];
54 [bwc showTranslateBubbleForWebContents:webContents
56 errorType:translate::TranslateErrors::NONE];
57 bubble = [bwc translateBubbleController];
59 InfoBubbleWindow* window = (InfoBubbleWindow*)[bubble window];
60 [window setAllowedAnimations:info_bubble::kAnimateNone];
63 chrome::testing::NSRunLoopRunAllPending();
64 bubble = [bwc translateBubbleController];