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

Side by Side Diff: chrome/browser/history/shortcuts_backend_unittest.cc

Issue 12546016: Remove the Extensions URLRequestContext (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: android webview init fix merged in. Created 7 years, 3 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
OLDNEW
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 "base/files/scoped_temp_dir.h" 5 #include "base/files/scoped_temp_dir.h"
6 #include "base/message_loop/message_loop.h"
7 #include "base/path_service.h" 6 #include "base/path_service.h"
7 #include "base/run_loop.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
11 #include "chrome/browser/history/shortcuts_backend.h" 11 #include "chrome/browser/history/shortcuts_backend.h"
12 #include "chrome/browser/history/shortcuts_backend_factory.h" 12 #include "chrome/browser/history/shortcuts_backend_factory.h"
13 #include "chrome/browser/history/shortcuts_database.h" 13 #include "chrome/browser/history/shortcuts_database.h"
14 #include "chrome/test/base/testing_profile.h" 14 #include "chrome/test/base/testing_profile.h"
15 #include "content/public/test/test_browser_thread.h" 15 #include "content/public/test/test_browser_thread_bundle.h"
16 #include "sql/statement.h" 16 #include "sql/statement.h"
17 17
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 19
20 using content::BrowserThread; 20 using content::BrowserThread;
21 21
22 namespace history { 22 namespace history {
23 23
24 const base::TimeDelta kMaxRequestWaitTimeout = base::TimeDelta::FromSeconds(1); 24 const base::TimeDelta kMaxRequestWaitTimeout = base::TimeDelta::FromSeconds(1);
25 25
26 class ShortcutsBackendTest : public testing::Test, 26 class ShortcutsBackendTest : public testing::Test,
27 public ShortcutsBackend::ShortcutsBackendObserver { 27 public ShortcutsBackend::ShortcutsBackendObserver {
28 public: 28 public:
29 ShortcutsBackendTest() 29 ShortcutsBackendTest()
30 : ui_thread_(BrowserThread::UI, &ui_message_loop_), 30 : load_notified_(false),
31 db_thread_(BrowserThread::DB),
32 load_notified_(false),
33 changed_notified_(false) {} 31 changed_notified_(false) {}
34 32
35 virtual void SetUp(); 33 virtual void SetUp();
36 virtual void TearDown(); 34 virtual void TearDown();
37 35
38 virtual void OnShortcutsLoaded() OVERRIDE; 36 virtual void OnShortcutsLoaded() OVERRIDE;
39 virtual void OnShortcutsChanged() OVERRIDE; 37 virtual void OnShortcutsChanged() OVERRIDE;
40 38
41 void InitBackend(); 39 void InitBackend();
42 40
41 content::TestBrowserThreadBundle thread_bundle_;
43 TestingProfile profile_; 42 TestingProfile profile_;
44 scoped_refptr<ShortcutsBackend> backend_; 43 scoped_refptr<ShortcutsBackend> backend_;
45 base::MessageLoopForUI ui_message_loop_;
46 content::TestBrowserThread ui_thread_;
47 content::TestBrowserThread db_thread_;
48 44
49 bool load_notified_; 45 bool load_notified_;
50 bool changed_notified_; 46 bool changed_notified_;
47 base::RunLoop on_loaded_loop_;
51 }; 48 };
52 49
53 void ShortcutsBackendTest::SetUp() { 50 void ShortcutsBackendTest::SetUp() {
54 db_thread_.Start();
55 ShortcutsBackendFactory::GetInstance()->SetTestingFactoryAndUse( 51 ShortcutsBackendFactory::GetInstance()->SetTestingFactoryAndUse(
56 &profile_, &ShortcutsBackendFactory::BuildProfileForTesting); 52 &profile_, &ShortcutsBackendFactory::BuildProfileForTesting);
57 backend_ = ShortcutsBackendFactory::GetForProfile(&profile_); 53 backend_ = ShortcutsBackendFactory::GetForProfile(&profile_);
58 ASSERT_TRUE(backend_.get()); 54 ASSERT_TRUE(backend_.get());
59 backend_->AddObserver(this); 55 backend_->AddObserver(this);
60 } 56 }
61 57
62 void ShortcutsBackendTest::TearDown() { 58 void ShortcutsBackendTest::TearDown() {
63 backend_->RemoveObserver(this); 59 backend_->RemoveObserver(this);
64 db_thread_.Stop();
65 } 60 }
66 61
67 void ShortcutsBackendTest::OnShortcutsLoaded() { 62 void ShortcutsBackendTest::OnShortcutsLoaded() {
68 load_notified_ = true; 63 load_notified_ = true;
69 base::MessageLoop::current()->Quit(); 64 on_loaded_loop_.Quit();
70 } 65 }
71 66
72 void ShortcutsBackendTest::OnShortcutsChanged() { 67 void ShortcutsBackendTest::OnShortcutsChanged() {
73 changed_notified_ = true; 68 changed_notified_ = true;
74 } 69 }
75 70
76 void ShortcutsBackendTest::InitBackend() { 71 void ShortcutsBackendTest::InitBackend() {
77 ShortcutsBackend* backend = 72 ShortcutsBackend* backend =
78 ShortcutsBackendFactory::GetForProfile(&profile_).get(); 73 ShortcutsBackendFactory::GetForProfile(&profile_).get();
79 ASSERT_TRUE(backend); 74 ASSERT_TRUE(backend);
80 ASSERT_FALSE(load_notified_); 75 ASSERT_FALSE(load_notified_);
81 ASSERT_FALSE(backend_->initialized()); 76 ASSERT_FALSE(backend_->initialized());
82 base::MessageLoop::current()->Run(); 77 on_loaded_loop_.Run();
83 EXPECT_TRUE(load_notified_); 78 EXPECT_TRUE(load_notified_);
84 EXPECT_TRUE(backend_->initialized()); 79 EXPECT_TRUE(backend_->initialized());
85 } 80 }
86 81
87 TEST_F(ShortcutsBackendTest, AddAndUpdateShortcut) { 82 TEST_F(ShortcutsBackendTest, AddAndUpdateShortcut) {
88 InitBackend(); 83 InitBackend();
89 EXPECT_FALSE(changed_notified_); 84 EXPECT_FALSE(changed_notified_);
90 ShortcutsBackend::Shortcut shortcut("BD85DBA2-8C29-49F9-84AE-48E1E90880DF", 85 ShortcutsBackend::Shortcut shortcut("BD85DBA2-8C29-49F9-84AE-48E1E90880DF",
91 ASCIIToUTF16("goog"), GURL("http://www.google.com"), 86 ASCIIToUTF16("goog"), GURL("http://www.google.com"),
92 ASCIIToUTF16("Google"), 87 ASCIIToUTF16("Google"),
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 std::vector<std::string> deleted_ids; 161 std::vector<std::string> deleted_ids;
167 deleted_ids.push_back(shortcut3.id); 162 deleted_ids.push_back(shortcut3.id);
168 deleted_ids.push_back(shortcut4.id); 163 deleted_ids.push_back(shortcut4.id);
169 164
170 EXPECT_TRUE(backend_->DeleteShortcutsWithIds(deleted_ids)); 165 EXPECT_TRUE(backend_->DeleteShortcutsWithIds(deleted_ids));
171 166
172 ASSERT_EQ(0U, shortcuts.size()); 167 ASSERT_EQ(0U, shortcuts.size());
173 } 168 }
174 169
175 } // namespace history 170 } // namespace history
OLDNEW
« no previous file with comments | « chrome/browser/extensions/menu_manager_unittest.cc ('k') | chrome/browser/history/shortcuts_database_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698