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 "base/files/scoped_temp_dir.h" | 5 #include "base/files/scoped_temp_dir.h" |
6 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
9 #include "base/time.h" | 9 #include "base/time.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 virtual void SetUp(); | 35 virtual void SetUp(); |
36 virtual void TearDown(); | 36 virtual void TearDown(); |
37 | 37 |
38 virtual void OnShortcutsLoaded() OVERRIDE; | 38 virtual void OnShortcutsLoaded() OVERRIDE; |
39 virtual void OnShortcutsChanged() OVERRIDE; | 39 virtual void OnShortcutsChanged() OVERRIDE; |
40 | 40 |
41 void InitBackend(); | 41 void InitBackend(); |
42 | 42 |
43 TestingProfile profile_; | 43 TestingProfile profile_; |
44 scoped_refptr<ShortcutsBackend> backend_; | 44 scoped_refptr<ShortcutsBackend> backend_; |
45 MessageLoopForUI ui_message_loop_; | 45 base::MessageLoopForUI ui_message_loop_; |
46 content::TestBrowserThread ui_thread_; | 46 content::TestBrowserThread ui_thread_; |
47 content::TestBrowserThread db_thread_; | 47 content::TestBrowserThread db_thread_; |
48 | 48 |
49 bool load_notified_; | 49 bool load_notified_; |
50 bool changed_notified_; | 50 bool changed_notified_; |
51 }; | 51 }; |
52 | 52 |
53 void ShortcutsBackendTest::SetUp() { | 53 void ShortcutsBackendTest::SetUp() { |
54 db_thread_.Start(); | 54 db_thread_.Start(); |
55 ShortcutsBackendFactory::GetInstance()->SetTestingFactoryAndUse( | 55 ShortcutsBackendFactory::GetInstance()->SetTestingFactoryAndUse( |
56 &profile_, &ShortcutsBackendFactory::BuildProfileForTesting); | 56 &profile_, &ShortcutsBackendFactory::BuildProfileForTesting); |
57 backend_ = ShortcutsBackendFactory::GetForProfile(&profile_); | 57 backend_ = ShortcutsBackendFactory::GetForProfile(&profile_); |
58 ASSERT_TRUE(backend_.get()); | 58 ASSERT_TRUE(backend_.get()); |
59 backend_->AddObserver(this); | 59 backend_->AddObserver(this); |
60 } | 60 } |
61 | 61 |
62 void ShortcutsBackendTest::TearDown() { | 62 void ShortcutsBackendTest::TearDown() { |
63 backend_->RemoveObserver(this); | 63 backend_->RemoveObserver(this); |
64 db_thread_.Stop(); | 64 db_thread_.Stop(); |
65 } | 65 } |
66 | 66 |
67 void ShortcutsBackendTest::OnShortcutsLoaded() { | 67 void ShortcutsBackendTest::OnShortcutsLoaded() { |
68 load_notified_ = true; | 68 load_notified_ = true; |
69 MessageLoop::current()->Quit(); | 69 base::MessageLoop::current()->Quit(); |
70 } | 70 } |
71 | 71 |
72 void ShortcutsBackendTest::OnShortcutsChanged() { | 72 void ShortcutsBackendTest::OnShortcutsChanged() { |
73 changed_notified_ = true; | 73 changed_notified_ = true; |
74 } | 74 } |
75 | 75 |
76 void ShortcutsBackendTest::InitBackend() { | 76 void ShortcutsBackendTest::InitBackend() { |
77 ShortcutsBackend* backend = ShortcutsBackendFactory::GetForProfile(&profile_); | 77 ShortcutsBackend* backend = ShortcutsBackendFactory::GetForProfile(&profile_); |
78 ASSERT_TRUE(backend); | 78 ASSERT_TRUE(backend); |
79 ASSERT_FALSE(load_notified_); | 79 ASSERT_FALSE(load_notified_); |
80 ASSERT_FALSE(backend_->initialized()); | 80 ASSERT_FALSE(backend_->initialized()); |
81 MessageLoop::current()->Run(); | 81 base::MessageLoop::current()->Run(); |
82 EXPECT_TRUE(load_notified_); | 82 EXPECT_TRUE(load_notified_); |
83 EXPECT_TRUE(backend_->initialized()); | 83 EXPECT_TRUE(backend_->initialized()); |
84 } | 84 } |
85 | 85 |
86 TEST_F(ShortcutsBackendTest, AddAndUpdateShortcut) { | 86 TEST_F(ShortcutsBackendTest, AddAndUpdateShortcut) { |
87 InitBackend(); | 87 InitBackend(); |
88 EXPECT_FALSE(changed_notified_); | 88 EXPECT_FALSE(changed_notified_); |
89 ShortcutsBackend::Shortcut shortcut("BD85DBA2-8C29-49F9-84AE-48E1E90880DF", | 89 ShortcutsBackend::Shortcut shortcut("BD85DBA2-8C29-49F9-84AE-48E1E90880DF", |
90 ASCIIToUTF16("goog"), GURL("http://www.google.com"), | 90 ASCIIToUTF16("goog"), GURL("http://www.google.com"), |
91 ASCIIToUTF16("Google"), | 91 ASCIIToUTF16("Google"), |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 std::vector<std::string> deleted_ids; | 165 std::vector<std::string> deleted_ids; |
166 deleted_ids.push_back(shortcut3.id); | 166 deleted_ids.push_back(shortcut3.id); |
167 deleted_ids.push_back(shortcut4.id); | 167 deleted_ids.push_back(shortcut4.id); |
168 | 168 |
169 EXPECT_TRUE(backend_->DeleteShortcutsWithIds(deleted_ids)); | 169 EXPECT_TRUE(backend_->DeleteShortcutsWithIds(deleted_ids)); |
170 | 170 |
171 ASSERT_EQ(0U, shortcuts.size()); | 171 ASSERT_EQ(0U, shortcuts.size()); |
172 } | 172 } |
173 | 173 |
174 } // namespace history | 174 } // namespace history |
OLD | NEW |