Check USB device path access when prompting users to select a device.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / autofill / new_credit_card_bubble_cocoa_unittest.mm
blob6cfa1226f53db8b065b9bf0ed4f73eecc8693d76
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.
5 #include "chrome/browser/ui/cocoa/autofill/new_credit_card_bubble_cocoa.h"
7 #import <Cocoa/Cocoa.h>
8 #include "base/compiler_specific.h"
9 #include "base/gtest_prod_util.h"
10 #include "base/mac/foundation_util.h"
11 #include "base/mac/scoped_nsautorelease_pool.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/weak_ptr.h"
14 #include "chrome/browser/ui/autofill/new_credit_card_bubble_controller.h"
15 #include "chrome/browser/ui/autofill/new_credit_card_bubble_view.h"
16 #include "chrome/browser/ui/browser.h"
17 #include "chrome/browser/ui/browser_window.h"
18 #include "chrome/browser/ui/cocoa/browser_window_controller.h"
19 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h"
20 #import "chrome/browser/ui/cocoa/info_bubble_window.h"
21 #include "chrome/test/base/testing_profile.h"
22 #include "content/public/browser/site_instance.h"
23 #include "content/public/browser/web_contents.h"
24 #include "testing/gtest_mac.h"
25 using autofill::NewCreditCardBubbleView;
26 using autofill::NewCreditCardBubbleController;
27 using autofill::NewCreditCardBubbleCocoa;
28 using content::SiteInstance;
29 using content::WebContents;
31 namespace autofill {
33 class NewCreditCardBubbleCocoaUnitTest : public CocoaProfileTest {
34  public:
35   void SetUp() override {
36     CocoaProfileTest::SetUp();
37     ASSERT_TRUE(profile());
39     site_instance_ = SiteInstance::Create(profile());
40   }
42   NewCreditCardBubbleController* CreateController(WebContents* contents) {
43     return new NewCreditCardBubbleController(contents);
44   }
46   WebContents* AppendToTabStrip() {
47     WebContents* web_contents = WebContents::Create(
48         content::WebContents::CreateParams(profile(), site_instance_.get()));
49     browser()->tab_strip_model()->AppendWebContents(
50         web_contents, /*foreground=*/true);
51     return web_contents;
52  }
54  private:
55   scoped_refptr<SiteInstance> site_instance_;
58 TEST_F(NewCreditCardBubbleCocoaUnitTest, CloseDeletes) {
59   base::mac::ScopedNSAutoreleasePool autorelease_pool;
60   NSWindow* window = browser()->window()->GetNativeWindow();
61   WebContents* web_contents = AppendToTabStrip();
62   NewCreditCardBubbleController* controller = CreateController(web_contents);
63   base::WeakPtr<NewCreditCardBubbleView> view =
64       NewCreditCardBubbleView::Create(controller);
65   autorelease_pool.Recycle();
66   ASSERT_TRUE(view.get());
68   // Now reach deep into |view| and pre-create the bubble controller...
69   NewCreditCardBubbleCocoa* cocoa_view =
70       static_cast<NewCreditCardBubbleCocoa*>(view.get());
71   cocoa_view->CreateCocoaController(window);
73   // ... so window animations can be disabled, guaranteeing prompt deallocation.
74   InfoBubbleWindow* bubble_window = cocoa_view->GetInfoBubbleWindow();
75   [bubble_window setAllowedAnimations:info_bubble::kAnimateNone];
77   view->Show();
78   autorelease_pool.Recycle();
79   ASSERT_TRUE(view.get());
81   view->Hide();
82   autorelease_pool.Recycle();
83   ASSERT_FALSE(view.get());
85   // |controller| gets deleted via the bubble closing.
88 }  // autofill