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

Side by Side Diff: components/password_manager/core/browser/export/password_exporter_unittest.cc

Issue 1193143003: Enable import/export of passwords into/from Password Manager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments Created 5 years, 5 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
OLDNEW
(Empty)
1
2 // Copyright 2014 The Chromium Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5
6 #include "components/password_manager/core/browser/export/password_exporter.h"
7
8 #include "base/bind.h"
9 #include "base/bind_helpers.h"
10 #include "base/files/file_util.h"
11 #include "base/memory/scoped_vector.h"
12 #include "base/message_loop/message_loop.h"
13 #include "base/run_loop.h"
14 #include "base/strings/stringprintf.h"
15 #include "base/strings/utf_string_conversions.h"
16 #include "components/autofill/core/common/password_form.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18
19 namespace password_manager {
20
21 class PasswordExporterTest : public testing::Test {
22 public:
23 PasswordExporterTest() : callback_called_(false) {}
24
25 protected:
26 ScopedVector<autofill::PasswordForm> ConstructTestPasswordForms() {
27 autofill::PasswordForm* password_form_ = new autofill::PasswordForm();
28 password_form_->origin = GURL("http://accounts.google.com/a/LoginAuth");
29 password_form_->username_value = base::ASCIIToUTF16("test@gmail.com");
30 password_form_->password_value = base::ASCIIToUTF16("test1");
31
32 ScopedVector<autofill::PasswordForm> password_forms;
33 password_forms.push_back(password_form_);
34 return password_forms.Pass();
35 }
36
37 void StartExportAndWaitUntilCompleteThenReadOutput(
38 const base::FilePath::StringType& extension,
39 ScopedVector<autofill::PasswordForm> passwords,
40 std::string* output) {
41 base::FilePath temporary_dir;
42 ASSERT_TRUE(base::CreateNewTempDirectory(base::FilePath::StringType(),
43 &temporary_dir));
44 base::FilePath output_file =
Garrett Casto 2015/07/07 22:11:09 Nit: Could you verify that if you don't have ".csv
45 temporary_dir.AppendASCII("passwords").AddExtension(extension);
46
47 PasswordExporter::Export(output_file, passwords.Pass(),
48 message_loop_.task_runner(),
49 base::Bind(&PasswordExporterTest::OnExportFinished,
50 base::Unretained(this)));
51
52 base::RunLoop run_loop;
53 run_loop.RunUntilIdle();
54
55 EXPECT_TRUE(callback_called_);
56 EXPECT_TRUE(base::ReadFileToString(output_file, output));
57 base::DeleteFile(temporary_dir, true);
58 }
59
60 void OnExportFinished() { callback_called_ = true; }
61
62 private:
63 base::MessageLoop message_loop_;
64 bool callback_called_;
65
66 DISALLOW_COPY_AND_ASSIGN(PasswordExporterTest);
67 };
68
69 TEST_F(PasswordExporterTest, CSVExport) {
70 #if defined(OS_WIN)
71 const char kLineEnding[] = "\r\n";
72 #else
73 const char kLineEnding[] = "\n";
74 #endif
75 std::string kExpectedCSVOutput = base::StringPrintf(
76 "name,url,username,password%s"
77 "accounts.google.com,http://accounts.google.com/a/"
78 "LoginAuth,test@gmail.com,test1%s",
79 kLineEnding, kLineEnding);
80
81 std::string output;
82 ASSERT_NO_FATAL_FAILURE(StartExportAndWaitUntilCompleteThenReadOutput(
83 FILE_PATH_LITERAL(".csv"), ConstructTestPasswordForms(), &output));
84 EXPECT_EQ(kExpectedCSVOutput, output);
85 }
86
87 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698