ccc1d5dc3f129b48b7cf00422687be91dc0884f5
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / cocoa / translate / translate_bubble_controller_unittest.mm
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   translate::TranslateStep step = translate::TRANSLATE_STEP_BEFORE_TRANSLATE;
50
51   TranslateBubbleController* bubble = [bwc translateBubbleController];
52   EXPECT_FALSE(bubble);
53
54   [bwc showTranslateBubbleForWebContents:webContents
55                                     step:step
56                                errorType:translate::TranslateErrors::NONE];
57   bubble = [bwc translateBubbleController];
58   EXPECT_TRUE(bubble);
59   InfoBubbleWindow* window = (InfoBubbleWindow*)[bubble window];
60   [window setAllowedAnimations:info_bubble::kAnimateNone];
61
62   [bubble close];
63   chrome::testing::NSRunLoopRunAllPending();
64   bubble = [bwc translateBubbleController];
65   EXPECT_FALSE(bubble);
66 }