Add a FrameHostMsg_BeginNavigation IPC
[chromium-blink-merge.git] / chrome / utility / importer / firefox_importer_unittest.cc
blob0ad20e10a358abfc9abf5e90c0bce3636d15b3a2
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
3 // found in the LICENSE file.
5 #include "base/files/file_path.h"
6 #include "base/files/scoped_temp_dir.h"
7 #include "base/path_service.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/common/chrome_paths.h"
10 #include "chrome/utility/importer/firefox_importer_unittest_utils.h"
11 #include "chrome/utility/importer/nss_decryptor.h"
12 #include "sql/connection.h"
13 #include "testing/gtest/include/gtest/gtest.h"
15 // TODO(jschuh): Disabled on Win64 build. http://crbug.com/179688
16 #if defined(OS_WIN) && defined(ARCH_CPU_X86_64)
17 #define MAYBE_NSS(x) DISABLED_##x
18 #else
19 #define MAYBE_NSS(x) x
20 #endif
22 // The following test requires the use of the NSSDecryptor, on OSX this needs
23 // to run in a separate process, so we use a proxy object so we can share the
24 // same test between platforms.
25 TEST(FirefoxImporterTest, MAYBE_NSS(Firefox3NSS3Decryptor)) {
26 base::FilePath nss_path;
27 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &nss_path));
28 #if defined(OS_MACOSX)
29 nss_path = nss_path.AppendASCII("firefox3_nss_mac");
30 #else
31 nss_path = nss_path.AppendASCII("firefox3_nss");
32 #endif // !OS_MACOSX
33 base::FilePath db_path;
34 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &db_path));
35 db_path = db_path.AppendASCII("firefox3_profile");
37 FFUnitTestDecryptorProxy decryptor_proxy;
38 ASSERT_TRUE(decryptor_proxy.Setup(nss_path));
40 ASSERT_TRUE(decryptor_proxy.DecryptorInit(nss_path, db_path));
41 EXPECT_EQ(base::ASCIIToUTF16("hello"),
42 decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECKa"
43 "jtRg4qFSHBAhv9luFkXgDJA=="));
44 // Test UTF-16 encoding.
45 EXPECT_EQ(base::WideToUTF16(L"\x4E2D"),
46 decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECLW"
47 "qqiccfQHWBAie74hxnULxlw=="));
50 // The following test verifies proper detection of authentication scheme in
51 // firefox's signons db. We insert two entries into moz_logins table. The first
52 // has httpRealm column filled with non-empty string, therefore resulting
53 // PasswordForm should have SCHEME_BASIC in scheme. The second entry has NULL
54 // httpRealm, so it should produce a SCHEME_HTML PasswordForm.
55 TEST(FirefoxImporterTest, MAYBE_NSS(FirefoxNSSDecryptorDeduceAuthScheme)) {
56 base::ScopedTempDir temp_dir;
57 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
58 base::FilePath signons_path = temp_dir.path().AppendASCII("signons.sqlite");
59 sql::Connection db_conn;
61 ASSERT_TRUE(db_conn.Open(signons_path));
63 ASSERT_TRUE(db_conn.Execute(
64 "CREATE TABLE moz_logins (id INTEGER PRIMARY KEY, hostname TEXT NOT "
65 "NULL, httpRealm TEXT, formSubmitURL TEXT, usernameField TEXT NOT NULL,"
66 "passwordField TEXT NOT NULL, encryptedUsername TEXT NOT NULL,"
67 "encryptedPassword TEXT NOT NULL, guid TEXT, encType INTEGER,"
68 "timeCreated INTEGER, timeLastUsed INTEGER, timePasswordChanged "
69 "INTEGER, timesUsed INTEGER)"));
71 ASSERT_TRUE(db_conn.Execute(
72 "CREATE TABLE moz_disabledHosts (id INTEGER PRIMARY KEY, hostname TEXT "
73 "UNIQUE ON CONFLICT REPLACE)"));
75 ASSERT_TRUE(db_conn.Execute(
76 "INSERT INTO 'moz_logins' VALUES(1,'http://server.com:1234',"
77 "'http_realm',NULL,'','','','','{bfa37106-a4dc-0a47-abb4-dafd507bf2db}',"
78 "1,1401883410959,1401883410959,1401883410959,1)"));
80 ASSERT_TRUE(db_conn.Execute(
81 "INSERT INTO 'moz_logins' VALUES(2,'http://server.com:1234',NULL,"
82 "'http://test2.server.com:1234/action','username','password','','',"
83 "'{71ad64fa-b5d4-cf4d-b390-2e4d56fe2aff}',1,1401883939239,"
84 "1401883939239, 1401883939239,1)"));
86 db_conn.Close();
88 base::FilePath nss_path;
89 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &nss_path));
90 #if defined(OS_MACOSX)
91 nss_path = nss_path.AppendASCII("firefox3_nss_mac");
92 #else
93 nss_path = nss_path.AppendASCII("firefox3_nss");
94 #endif // !OS_MACOSX
95 base::FilePath db_path;
96 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &db_path));
97 db_path = db_path.AppendASCII("firefox3_profile");
99 FFUnitTestDecryptorProxy decryptor_proxy;
100 ASSERT_TRUE(decryptor_proxy.Setup(nss_path));
102 ASSERT_TRUE(decryptor_proxy.DecryptorInit(nss_path, db_path));
103 std::vector<autofill::PasswordForm> forms =
104 decryptor_proxy.ParseSignons(signons_path);
106 ASSERT_EQ(2u, forms.size());
107 EXPECT_EQ(autofill::PasswordForm::SCHEME_BASIC, forms[0].scheme);
108 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, forms[1].scheme);