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

Side by Side Diff: chrome/browser/importer/importer_unittest.cc

Issue 345037: Fifth patch in getting rid of caching MessageLoop pointers. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "testing/gtest/include/gtest/gtest.h" 5 #include "testing/gtest/include/gtest/gtest.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <unknwn.h> 8 #include <unknwn.h>
9 #include <intshcut.h> 9 #include <intshcut.h>
10 #include <pstore.h> 10 #include <pstore.h>
11 #include <urlhist.h> 11 #include <urlhist.h>
12 #include <shlguid.h> 12 #include <shlguid.h>
13 #include <vector> 13 #include <vector>
14 14
15 #include "app/win_util.h" 15 #include "app/win_util.h"
16 #include "base/file_util.h" 16 #include "base/file_util.h"
17 #include "base/message_loop.h" 17 #include "base/message_loop.h"
18 #include "base/path_service.h" 18 #include "base/path_service.h"
19 #include "base/scoped_comptr_win.h" 19 #include "base/scoped_comptr_win.h"
20 #include "base/stl_util-inl.h" 20 #include "base/stl_util-inl.h"
21 #include "chrome/browser/chrome_thread.h"
21 #include "chrome/browser/importer/ie_importer.h" 22 #include "chrome/browser/importer/ie_importer.h"
22 #include "chrome/browser/importer/importer.h" 23 #include "chrome/browser/importer/importer.h"
23 #include "chrome/browser/importer/importer_bridge.h" 24 #include "chrome/browser/importer/importer_bridge.h"
24 #include "chrome/browser/password_manager/ie7_password.h" 25 #include "chrome/browser/password_manager/ie7_password.h"
25 #include "chrome/browser/profile.h" 26 #include "chrome/browser/profile.h"
26 #include "chrome/browser/search_engines/template_url.h" 27 #include "chrome/browser/search_engines/template_url.h"
27 #include "chrome/common/chrome_paths.h" 28 #include "chrome/common/chrome_paths.h"
28 #include "webkit/glue/password_form.h" 29 #include "webkit/glue/password_form.h"
29 30
30 using webkit_glue::PasswordForm; 31 using webkit_glue::PasswordForm;
31 32
32 class ImporterTest : public testing::Test { 33 class ImporterTest : public testing::Test {
33 public: 34 public:
35 ImporterTest()
36 : ui_thread_(ChromeThread::UI, &message_loop_),
37 file_thread_(ChromeThread::FILE, &message_loop_) {}
34 protected: 38 protected:
35 virtual void SetUp() { 39 virtual void SetUp() {
36 // Creates a new profile in a new subdirectory in the temp directory. 40 // Creates a new profile in a new subdirectory in the temp directory.
37 ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &test_path_)); 41 ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &test_path_));
38 file_util::AppendToPath(&test_path_, L"ImporterTest"); 42 file_util::AppendToPath(&test_path_, L"ImporterTest");
39 file_util::Delete(test_path_, true); 43 file_util::Delete(test_path_, true);
40 CreateDirectory(test_path_.c_str(), NULL); 44 CreateDirectory(test_path_.c_str(), NULL);
41 profile_path_ = test_path_; 45 profile_path_ = test_path_;
42 file_util::AppendToPath(&profile_path_, L"profile"); 46 file_util::AppendToPath(&profile_path_, L"profile");
43 CreateDirectory(profile_path_.c_str(), NULL); 47 CreateDirectory(profile_path_.c_str(), NULL);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 } 81 }
78 ASSERT_TRUE(file_util::CopyDirectory(data_path, 82 ASSERT_TRUE(file_util::CopyDirectory(data_path,
79 search_engine_path, false)); 83 search_engine_path, false));
80 } 84 }
81 85
82 MessageLoop* loop = MessageLoop::current(); 86 MessageLoop* loop = MessageLoop::current();
83 ProfileInfo profile_info; 87 ProfileInfo profile_info;
84 profile_info.browser_type = FIREFOX3; 88 profile_info.browser_type = FIREFOX3;
85 profile_info.app_path = app_path_; 89 profile_info.app_path = app_path_;
86 profile_info.source_path = profile_path_; 90 profile_info.source_path = profile_path_;
87 scoped_refptr<ImporterHost> host = new ImporterHost(loop); 91 scoped_refptr<ImporterHost> host = new ImporterHost();
88 host->SetObserver(observer); 92 host->SetObserver(observer);
89 int items = HISTORY | PASSWORDS | FAVORITES; 93 int items = HISTORY | PASSWORDS | FAVORITES;
90 if (import_search_plugins) 94 if (import_search_plugins)
91 items = items | SEARCH_ENGINES; 95 items = items | SEARCH_ENGINES;
92 loop->PostTask(FROM_HERE, NewRunnableMethod(host.get(), 96 loop->PostTask(FROM_HERE, NewRunnableMethod(host.get(),
93 &ImporterHost::StartImportSettings, profile_info, 97 &ImporterHost::StartImportSettings, profile_info,
94 static_cast<Profile*>(NULL), items, writer, true)); 98 static_cast<Profile*>(NULL), items, writer, true));
95 loop->Run(); 99 loop->Run();
96 } 100 }
97 101
98 MessageLoopForUI message_loop_; 102 MessageLoopForUI message_loop_;
103 ChromeThread ui_thread_;
104 ChromeThread file_thread_;
99 std::wstring test_path_; 105 std::wstring test_path_;
100 std::wstring profile_path_; 106 std::wstring profile_path_;
101 std::wstring app_path_; 107 std::wstring app_path_;
102 }; 108 };
103 109
104 const int kMaxPathSize = 5; 110 const int kMaxPathSize = 5;
105 111
106 typedef struct { 112 typedef struct {
107 const bool in_toolbar; 113 const bool in_toolbar;
108 const int path_size; 114 const int path_size;
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 // Sets up a special history link. 377 // Sets up a special history link.
372 ScopedComPtr<IUrlHistoryStg2> url_history_stg2; 378 ScopedComPtr<IUrlHistoryStg2> url_history_stg2;
373 res = url_history_stg2.CreateInstance(CLSID_CUrlHistory, NULL, 379 res = url_history_stg2.CreateInstance(CLSID_CUrlHistory, NULL,
374 CLSCTX_INPROC_SERVER); 380 CLSCTX_INPROC_SERVER);
375 ASSERT_TRUE(res == S_OK); 381 ASSERT_TRUE(res == S_OK);
376 res = url_history_stg2->AddUrl(kIEIdentifyUrl, kIEIdentifyTitle, 0); 382 res = url_history_stg2->AddUrl(kIEIdentifyUrl, kIEIdentifyTitle, 0);
377 ASSERT_TRUE(res == S_OK); 383 ASSERT_TRUE(res == S_OK);
378 384
379 // Starts to import the above settings. 385 // Starts to import the above settings.
380 MessageLoop* loop = MessageLoop::current(); 386 MessageLoop* loop = MessageLoop::current();
381 scoped_refptr<ImporterHost> host = new ImporterHost(loop); 387 scoped_refptr<ImporterHost> host = new ImporterHost();
382 388
383 TestObserver* observer = new TestObserver(); 389 TestObserver* observer = new TestObserver();
384 host->SetObserver(observer); 390 host->SetObserver(observer);
385 ProfileInfo profile_info; 391 ProfileInfo profile_info;
386 profile_info.browser_type = MS_IE; 392 profile_info.browser_type = MS_IE;
387 profile_info.source_path = test_path_; 393 profile_info.source_path = test_path_;
388 394
389 loop->PostTask(FROM_HERE, NewRunnableMethod(host.get(), 395 loop->PostTask(FROM_HERE, NewRunnableMethod(host.get(),
390 &ImporterHost::StartImportSettings, profile_info, 396 &ImporterHost::StartImportSettings, profile_info,
391 static_cast<Profile*>(NULL), HISTORY | PASSWORDS | FAVORITES, observer, 397 static_cast<Profile*>(NULL), HISTORY | PASSWORDS | FAVORITES, observer,
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); 653 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path));
648 file_util::AppendToPath(&data_path, L"firefox2_searchplugins"); 654 file_util::AppendToPath(&data_path, L"firefox2_searchplugins");
649 if (!file_util::PathExists(FilePath::FromWStringHack(data_path))) { 655 if (!file_util::PathExists(FilePath::FromWStringHack(data_path))) {
650 // TODO(maruel): Create test data that we can open source! 656 // TODO(maruel): Create test data that we can open source!
651 LOG(ERROR) << L"Missing internal test data"; 657 LOG(ERROR) << L"Missing internal test data";
652 return; 658 return;
653 } 659 }
654 ASSERT_TRUE(file_util::CopyDirectory(data_path, search_engine_path, false)); 660 ASSERT_TRUE(file_util::CopyDirectory(data_path, search_engine_path, false));
655 661
656 MessageLoop* loop = MessageLoop::current(); 662 MessageLoop* loop = MessageLoop::current();
657 scoped_refptr<ImporterHost> host = new ImporterHost(loop); 663 scoped_refptr<ImporterHost> host = new ImporterHost();
658 FirefoxObserver* observer = new FirefoxObserver(); 664 FirefoxObserver* observer = new FirefoxObserver();
659 host->SetObserver(observer); 665 host->SetObserver(observer);
660 ProfileInfo profile_info; 666 ProfileInfo profile_info;
661 profile_info.browser_type = FIREFOX2; 667 profile_info.browser_type = FIREFOX2;
662 profile_info.app_path = app_path_; 668 profile_info.app_path = app_path_;
663 profile_info.source_path = profile_path_; 669 profile_info.source_path = profile_path_;
664 670
665 loop->PostTask(FROM_HERE, NewRunnableMethod(host.get(), 671 loop->PostTask(FROM_HERE, NewRunnableMethod(host.get(),
666 &ImporterHost::StartImportSettings, profile_info, 672 &ImporterHost::StartImportSettings, profile_info,
667 static_cast<Profile*>(NULL), 673 static_cast<Profile*>(NULL),
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 true); 849 true);
844 } 850 }
845 851
846 TEST_F(ImporterTest, Firefox35Importer) { 852 TEST_F(ImporterTest, Firefox35Importer) {
847 bool import_search_engines = false; 853 bool import_search_engines = false;
848 scoped_refptr<Firefox3Observer> observer = 854 scoped_refptr<Firefox3Observer> observer =
849 new Firefox3Observer(import_search_engines); 855 new Firefox3Observer(import_search_engines);
850 Firefox3xImporterTest(L"firefox35_profile", observer.get(), observer.get(), 856 Firefox3xImporterTest(L"firefox35_profile", observer.get(), observer.get(),
851 import_search_engines); 857 import_search_engines);
852 } 858 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698