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