OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/search_engines/template_url_service_factory.h" | 5 #include "chrome/browser/search_engines/template_url_service_factory.h" |
6 #include "chrome/browser/ui/views/first_run_bubble.h" | 6 #include "chrome/browser/ui/views/first_run_bubble.h" |
| 7 #include "chrome/test/base/testing_browser_process.h" |
7 #include "chrome/test/base/testing_profile.h" | 8 #include "chrome/test/base/testing_profile.h" |
8 #include "components/search_engines/template_url.h" | 9 #include "components/search_engines/template_url.h" |
9 #include "components/search_engines/template_url_service.h" | 10 #include "components/search_engines/template_url_service.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "ui/views/test/views_test_base.h" | 12 #include "ui/views/test/views_test_base.h" |
12 #include "ui/views/view.h" | 13 #include "ui/views/view.h" |
13 #include "ui/views/widget/widget.h" | 14 #include "ui/views/widget/widget.h" |
14 | 15 |
15 class FirstRunBubbleTest : public views::ViewsTestBase { | 16 class FirstRunBubbleTest : public views::ViewsTestBase { |
16 public: | 17 public: |
17 FirstRunBubbleTest(); | 18 FirstRunBubbleTest(); |
18 ~FirstRunBubbleTest() override; | 19 ~FirstRunBubbleTest() override; |
19 | 20 |
20 // Overrides from views::ViewsTestBase: | 21 // Overrides from views::ViewsTestBase: |
21 void SetUp() override; | 22 void SetUp() override; |
| 23 void TearDown() override; |
22 | 24 |
23 protected: | 25 protected: |
24 TestingProfile* profile() { return &profile_; } | 26 TestingProfile* profile() { return profile_.get(); } |
25 | 27 |
26 private: | 28 private: |
27 TestingProfile profile_; | 29 scoped_ptr<TestingProfile> profile_; |
28 | 30 |
29 DISALLOW_COPY_AND_ASSIGN(FirstRunBubbleTest); | 31 DISALLOW_COPY_AND_ASSIGN(FirstRunBubbleTest); |
30 }; | 32 }; |
31 | 33 |
32 FirstRunBubbleTest::FirstRunBubbleTest() {} | 34 FirstRunBubbleTest::FirstRunBubbleTest() {} |
33 FirstRunBubbleTest::~FirstRunBubbleTest() {} | 35 FirstRunBubbleTest::~FirstRunBubbleTest() {} |
34 | 36 |
35 void FirstRunBubbleTest::SetUp() { | 37 void FirstRunBubbleTest::SetUp() { |
36 ViewsTestBase::SetUp(); | 38 ViewsTestBase::SetUp(); |
| 39 profile_.reset(new TestingProfile()); |
37 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 40 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
38 &profile_, &TemplateURLServiceFactory::BuildInstanceFor); | 41 profile_.get(), &TemplateURLServiceFactory::BuildInstanceFor); |
39 TemplateURLService* turl_model = | 42 TemplateURLService* turl_model = |
40 TemplateURLServiceFactory::GetForProfile(&profile_); | 43 TemplateURLServiceFactory::GetForProfile(profile_.get()); |
41 turl_model->Load(); | 44 turl_model->Load(); |
42 } | 45 } |
43 | 46 |
| 47 void FirstRunBubbleTest::TearDown() { |
| 48 ViewsTestBase::TearDown(); |
| 49 profile_.reset(); |
| 50 TestingBrowserProcess::DeleteInstance(); |
| 51 } |
| 52 |
44 TEST_F(FirstRunBubbleTest, CreateAndClose) { | 53 TEST_F(FirstRunBubbleTest, CreateAndClose) { |
45 // Create the anchor and parent widgets. | 54 // Create the anchor and parent widgets. |
46 views::Widget::InitParams params = | 55 views::Widget::InitParams params = |
47 CreateParams(views::Widget::InitParams::TYPE_WINDOW); | 56 CreateParams(views::Widget::InitParams::TYPE_WINDOW); |
48 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 57 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
49 scoped_ptr<views::Widget> anchor_widget(new views::Widget); | 58 scoped_ptr<views::Widget> anchor_widget(new views::Widget); |
50 anchor_widget->Init(params); | 59 anchor_widget->Init(params); |
51 anchor_widget->Show(); | 60 anchor_widget->Show(); |
52 | 61 |
53 FirstRunBubble* delegate = | 62 FirstRunBubble* delegate = |
54 FirstRunBubble::ShowBubble(NULL, anchor_widget->GetContentsView()); | 63 FirstRunBubble::ShowBubble(NULL, anchor_widget->GetContentsView()); |
55 EXPECT_TRUE(delegate != NULL); | 64 EXPECT_TRUE(delegate != NULL); |
56 delegate->GetWidget()->CloseNow(); | 65 delegate->GetWidget()->CloseNow(); |
57 } | 66 } |
OLD | NEW |