Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(245)

Side by Side Diff: chrome/browser/ui/views/first_run_search_engine_view_unittest.cc

Issue 9285002: Remove the first-run search engine dialog/ballot. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync and merge. Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/views/first_run_search_engine_view.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/views/first_run_search_engine_view.h"
6
7 #include "base/threading/thread.h"
8 #include "chrome/browser/search_engines/template_url.h"
9 #include "chrome/browser/search_engines/template_url_service.h"
10 #include "chrome/browser/search_engines/template_url_service_factory.h"
11 #include "chrome/common/chrome_notification_types.h"
12 #include "chrome/test/base/testing_profile.h"
13 #include "chrome/test/base/ui_test_utils.h"
14 #include "content/public/browser/notification_service.h"
15 #include "content/test/test_browser_thread.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "ui/views/focus/accelerator_handler.h"
18 #include "ui/views/test/views_test_base.h"
19 #include "ui/views/widget/widget.h"
20
21 typedef views::ViewsTestBase FirstRunSearchEngineViewTest;
22
23 TEST_F(FirstRunSearchEngineViewTest, ClosingSelectsFirstEngine) {
24 // Create the first run search engine selector, and just close the window.
25 // The first engine in the vector returned by GetTemplateURLs should be set as
26 // the default engine.
27 TestingProfile profile;
28 profile.CreateTemplateURLService();
29 profile.BlockUntilTemplateURLServiceLoaded();
30
31 // Set a dummy provider as the default so we can verify something changed.
32 TemplateURLService* service =
33 TemplateURLServiceFactory::GetForProfile(&profile);
34 ASSERT_TRUE(service != NULL);
35 EXPECT_EQ(NULL, service->GetDefaultSearchProvider());
36 TemplateURL* d1 = new TemplateURL;
37 TemplateURL* d2 = new TemplateURL;
38 TemplateURL* d3 = new TemplateURL;
39 service->Add(d1);
40 service->Add(d2);
41 service->Add(d3);
42 service->SetDefaultSearchProvider(d3);
43
44 FirstRunSearchEngineView* contents =
45 new FirstRunSearchEngineView(&profile, false);
46 contents->set_quit_on_closing(false);
47 views::Widget* window = views::Widget::CreateWindow(contents);
48 window->Show();
49 window->Close();
50 RunPendingMessages(); // Allows the window to be destroyed after Close();
51
52 TemplateURLService::TemplateURLVector template_urls =
53 service->GetTemplateURLs();
54 ASSERT_TRUE(!template_urls.empty());
55 EXPECT_EQ(template_urls.front(), service->GetDefaultSearchProvider());
56 }
57
58 // http://code.google.com/p/chromium/issues/detail?id=111062
59 TEST_F(FirstRunSearchEngineViewTest,
60 FLAKY_ClosingBeforeServiceLoadedAbortsClose) {
61 // This ensures the current thread is named the UI thread, so code that checks
62 // that this is the UI thread doesn't assert.
63 base::Thread db_thread("tempdbthread");
64 db_thread.Start();
65 content::TestBrowserThread ui_thread(content::BrowserThread::UI,
66 message_loop());
67 content::TestBrowserThread db_test_thread(content::BrowserThread::DB,
68 db_thread.message_loop());
69
70 TestingProfile profile;
71 // We need to initialize the web database before accessing the template url
72 // service otherwise the template url service will init itself synchronously
73 // and appear to be loaded.
74 profile.CreateWebDataService(false);
75 profile.CreateTemplateURLService();
76
77 // Instead of giving the template url service a chance to load, try and close
78 // the window immediately.
79 FirstRunSearchEngineView* contents =
80 new FirstRunSearchEngineView(&profile, false);
81 contents->set_quit_on_closing(false);
82 views::Widget* window = views::Widget::CreateWindow(contents);
83 window->Show();
84 EXPECT_TRUE(window->IsVisible());
85 window->Close();
86 // The window wouldn't actually be closed until a return to the message loop,
87 // which we don't want to spin here because the window shouldn't have closed
88 // in the correct case. The window is however actually hidden immediately when
89 // the window is allowed to close, so we can test for visibility to make sure
90 // it hasn't.
91 EXPECT_TRUE(window->IsVisible());
92
93 // Now let the template url service a chance to load.
94 ui_test_utils::WindowedNotificationObserver service_load_observer(
95 chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED,
96 content::NotificationService::AllSources());
97 service_load_observer.Wait();
98
99 // .. and try and close the window. It should be allowed to now.
100 window->Close();
101 EXPECT_FALSE(window->IsVisible());
102
103 // Allow the window to actually close.
104 RunPendingMessages();
105
106 // Verify goodness. Because we actually went to the trouble of starting the
107 // WebDB, we will have real data in the model, so we can verify a choice was
108 // made without having to seed the model with dummy data.
109 TemplateURLService* service =
110 TemplateURLServiceFactory::GetForProfile(&profile);
111 ASSERT_TRUE(service != NULL);
112 EXPECT_TRUE(service->GetDefaultSearchProvider() != NULL);
113 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/first_run_search_engine_view.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698