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

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

Issue 14143010: Introduce IEImporterTestRegistryOverrider to be able to override the registry for a test and flag t… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: grammar Created 7 years, 8 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 // The order of these includes is important. 5 // The order of these includes is important.
6 #include <windows.h> 6 #include <windows.h>
7 #include <unknwn.h> 7 #include <unknwn.h>
8 #include <intshcut.h> 8 #include <intshcut.h>
9 #include <shlguid.h> 9 #include <shlguid.h>
10 #include <urlhist.h> 10 #include <urlhist.h>
(...skipping 12 matching lines...) Expand all
23 #include "base/stl_util.h" 23 #include "base/stl_util.h"
24 #include "base/string16.h" 24 #include "base/string16.h"
25 #include "base/string_util.h" 25 #include "base/string_util.h"
26 #include "base/utf_string_conversions.h" 26 #include "base/utf_string_conversions.h"
27 #include "base/win/registry.h" 27 #include "base/win/registry.h"
28 #include "base/win/scoped_comptr.h" 28 #include "base/win/scoped_comptr.h"
29 #include "base/win/scoped_propvariant.h" 29 #include "base/win/scoped_propvariant.h"
30 #include "base/win/windows_version.h" 30 #include "base/win/windows_version.h"
31 #include "chrome/browser/history/history_types.h" 31 #include "chrome/browser/history/history_types.h"
32 #include "chrome/browser/importer/ie_importer.h" 32 #include "chrome/browser/importer/ie_importer.h"
33 #include "chrome/browser/importer/ie_importer_test_registry_overrider_win.h"
33 #include "chrome/browser/importer/importer_bridge.h" 34 #include "chrome/browser/importer/importer_bridge.h"
34 #include "chrome/browser/importer/importer_data_types.h" 35 #include "chrome/browser/importer/importer_data_types.h"
35 #include "chrome/browser/importer/importer_host.h" 36 #include "chrome/browser/importer/importer_host.h"
36 #include "chrome/browser/importer/importer_progress_observer.h" 37 #include "chrome/browser/importer/importer_progress_observer.h"
37 #include "chrome/browser/importer/importer_unittest_utils.h" 38 #include "chrome/browser/importer/importer_unittest_utils.h"
38 #include "chrome/browser/importer/pstore_declarations.h" 39 #include "chrome/browser/importer/pstore_declarations.h"
39 #include "chrome/browser/search_engines/template_url.h" 40 #include "chrome/browser/search_engines/template_url.h"
40 #include "chrome/browser/ui/browser.h" 41 #include "chrome/browser/ui/browser.h"
41 #include "chrome/common/chrome_paths.h" 42 #include "chrome/common/chrome_paths.h"
42 #include "chrome/test/base/in_process_browser_test.h" 43 #include "chrome/test/base/in_process_browser_test.h"
43 #include "chrome/test/base/testing_profile.h" 44 #include "chrome/test/base/testing_profile.h"
44 #include "content/public/common/password_form.h" 45 #include "content/public/common/password_form.h"
45 #include "testing/gtest/include/gtest/gtest.h" 46 #include "testing/gtest/include/gtest/gtest.h"
46 47
47 namespace { 48 namespace {
48 49
49 const char16 kUnitTestRegistrySubKey[] = L"SOFTWARE\\Chromium Unit Tests";
50 const char16 kUnitTestUserOverrideSubKey[] =
51 L"SOFTWARE\\Chromium Unit Tests\\HKCU Override";
52
53 const BookmarkInfo kIEBookmarks[] = { 50 const BookmarkInfo kIEBookmarks[] = {
54 {true, 2, {L"Links", L"SubFolderOfLinks"}, 51 {true, 2, {L"Links", L"SubFolderOfLinks"},
55 L"SubLink", 52 L"SubLink",
56 "http://www.links-sublink.com/"}, 53 "http://www.links-sublink.com/"},
57 {true, 1, {L"Links"}, 54 {true, 1, {L"Links"},
58 L"TheLink", 55 L"TheLink",
59 "http://www.links-thelink.com/"}, 56 "http://www.links-thelink.com/"},
60 {false, 0, {}, 57 {false, 0, {},
61 L"Google Home Page", 58 L"Google Home Page",
62 "http://www.google.com/"}, 59 "http://www.google.com/"},
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 }; 406 };
410 407
411 } // namespace 408 } // namespace
412 409
413 // These tests need to be browser tests in order to be able to run the OOP 410 // These tests need to be browser tests in order to be able to run the OOP
414 // import (via ExternalProcessImporterHost) which launches a utility process. 411 // import (via ExternalProcessImporterHost) which launches a utility process.
415 class IEImporterBrowserTest : public InProcessBrowserTest { 412 class IEImporterBrowserTest : public InProcessBrowserTest {
416 protected: 413 protected:
417 virtual void SetUp() OVERRIDE { 414 virtual void SetUp() OVERRIDE {
418 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 415 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
419 StartRegistryOverride(); 416
417 // Turn the override on for this process and flag child processes that they
418 // should do so as well.
419 ASSERT_TRUE(test_registry_overrider_.SetRegistryOverride());
420 420
421 // This will launch the browser test and thus needs to happen last. 421 // This will launch the browser test and thus needs to happen last.
422 InProcessBrowserTest::SetUp(); 422 InProcessBrowserTest::SetUp();
423 } 423 }
424 424
425 virtual void TearDown() OVERRIDE {
426 EndRegistryOverride();
427 }
428
429 void StartRegistryOverride() {
430 EXPECT_EQ(ERROR_SUCCESS, RegOverridePredefKey(HKEY_CURRENT_USER, NULL));
431 temp_hkcu_hive_key_.Create(HKEY_CURRENT_USER,
432 kUnitTestUserOverrideSubKey,
433 KEY_ALL_ACCESS);
434 EXPECT_TRUE(temp_hkcu_hive_key_.Valid());
435 EXPECT_EQ(ERROR_SUCCESS,
436 RegOverridePredefKey(HKEY_CURRENT_USER,
437 temp_hkcu_hive_key_.Handle()));
438 }
439
440 void EndRegistryOverride() {
441 EXPECT_EQ(ERROR_SUCCESS, RegOverridePredefKey(HKEY_CURRENT_USER, NULL));
442 temp_hkcu_hive_key_.Close();
443 base::win::RegKey key(HKEY_CURRENT_USER, kUnitTestRegistrySubKey,
444 KEY_ALL_ACCESS);
445 key.DeleteKey(L"");
446 }
447
448 base::ScopedTempDir temp_dir_; 425 base::ScopedTempDir temp_dir_;
449 base::win::RegKey temp_hkcu_hive_key_; 426 IEImporterTestRegistryOverrider test_registry_overrider_;
450 }; 427 };
451 428
452 IN_PROC_BROWSER_TEST_F(IEImporterBrowserTest, IEImporter) { 429 IN_PROC_BROWSER_TEST_F(IEImporterBrowserTest, IEImporter) {
453 // Sets up a favorites folder. 430 // Sets up a favorites folder.
454 base::FilePath path = temp_dir_.path().AppendASCII("Favorites"); 431 base::FilePath path = temp_dir_.path().AppendASCII("Favorites");
455 CreateDirectory(path.value().c_str(), NULL); 432 CreateDirectory(path.value().c_str(), NULL);
456 CreateDirectory(path.AppendASCII("SubFolder").value().c_str(), NULL); 433 CreateDirectory(path.AppendASCII("SubFolder").value().c_str(), NULL);
457 base::FilePath links_path = path.AppendASCII("Links"); 434 base::FilePath links_path = path.AppendASCII("Links");
458 CreateDirectory(links_path.value().c_str(), NULL); 435 CreateDirectory(links_path.value().c_str(), NULL);
459 CreateDirectory(links_path.AppendASCII("SubFolderOfLinks").value().c_str(), 436 CreateDirectory(links_path.AppendASCII("SubFolderOfLinks").value().c_str(),
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 // TODO(gab): Use ExternalProcessImporterHost on Windows. 490 // TODO(gab): Use ExternalProcessImporterHost on Windows.
514 scoped_refptr<ImporterHost> host(new ImporterHost); 491 scoped_refptr<ImporterHost> host(new ImporterHost);
515 TestObserver* observer = new TestObserver(); 492 TestObserver* observer = new TestObserver();
516 host->SetObserver(observer); 493 host->SetObserver(observer);
517 494
518 importer::SourceProfile source_profile; 495 importer::SourceProfile source_profile;
519 source_profile.importer_type = importer::TYPE_IE; 496 source_profile.importer_type = importer::TYPE_IE;
520 source_profile.source_path = temp_dir_.path(); 497 source_profile.source_path = temp_dir_.path();
521 498
522 // IUrlHistoryStg2::AddUrl seems to reset the override. Ensure it here. 499 // IUrlHistoryStg2::AddUrl seems to reset the override. Ensure it here.
523 StartRegistryOverride(); 500 ASSERT_TRUE(test_registry_overrider_.SetRegistryOverride());
524 501
525 host->StartImportSettings( 502 host->StartImportSettings(
526 source_profile, 503 source_profile,
527 browser()->profile(), 504 browser()->profile(),
528 importer::HISTORY | importer::PASSWORDS | importer::FAVORITES, 505 importer::HISTORY | importer::PASSWORDS | importer::FAVORITES,
529 observer); 506 observer);
530 MessageLoop::current()->Run(); 507 MessageLoop::current()->Run();
531 508
532 // Cleans up. 509 // Cleans up.
533 url_history_stg2->DeleteUrl(kIEIdentifyUrl, 0); 510 url_history_stg2->DeleteUrl(kIEIdentifyUrl, 0);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 source_profile.source_path = temp_dir_.path(); 576 source_profile.source_path = temp_dir_.path();
600 577
601 host->StartImportSettings( 578 host->StartImportSettings(
602 source_profile, 579 source_profile,
603 browser()->profile(), 580 browser()->profile(),
604 importer::FAVORITES, 581 importer::FAVORITES,
605 observer); 582 observer);
606 MessageLoop::current()->Run(); 583 MessageLoop::current()->Run();
607 } 584 }
608 } 585 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698