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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: components/password_manager/core/browser/export/password_exporter_unittest.cc
diff --git a/components/password_manager/core/browser/export/password_exporter_unittest.cc b/components/password_manager/core/browser/export/password_exporter_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f92ba9c4ac27a53ffb6eeba856069fef0543c662
--- /dev/null
+++ b/components/password_manager/core/browser/export/password_exporter_unittest.cc
@@ -0,0 +1,87 @@
+
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/password_manager/core/browser/export/password_exporter.h"
+
+#include "base/bind.h"
+#include "base/bind_helpers.h"
+#include "base/files/file_util.h"
+#include "base/memory/scoped_vector.h"
+#include "base/message_loop/message_loop.h"
+#include "base/run_loop.h"
+#include "base/strings/stringprintf.h"
+#include "base/strings/utf_string_conversions.h"
+#include "components/autofill/core/common/password_form.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace password_manager {
+
+class PasswordExporterTest : public testing::Test {
+ public:
+ PasswordExporterTest() : callback_called_(false) {}
+
+ protected:
+ ScopedVector<autofill::PasswordForm> ConstructTestPasswordForms() {
+ autofill::PasswordForm* password_form_ = new autofill::PasswordForm();
+ password_form_->origin = GURL("http://accounts.google.com/a/LoginAuth");
+ password_form_->username_value = base::ASCIIToUTF16("test@gmail.com");
+ password_form_->password_value = base::ASCIIToUTF16("test1");
+
+ ScopedVector<autofill::PasswordForm> password_forms;
+ password_forms.push_back(password_form_);
+ return password_forms.Pass();
+ }
+
+ void StartExportAndWaitUntilCompleteThenReadOutput(
+ const base::FilePath::StringType& extension,
+ ScopedVector<autofill::PasswordForm> passwords,
+ std::string* output) {
+ base::FilePath temporary_dir;
+ ASSERT_TRUE(base::CreateNewTempDirectory(base::FilePath::StringType(),
+ &temporary_dir));
+ base::FilePath output_file =
Garrett Casto 2015/07/07 22:11:09 Nit: Could you verify that if you don't have ".csv
+ temporary_dir.AppendASCII("passwords").AddExtension(extension);
+
+ PasswordExporter::Export(output_file, passwords.Pass(),
+ message_loop_.task_runner(),
+ base::Bind(&PasswordExporterTest::OnExportFinished,
+ base::Unretained(this)));
+
+ base::RunLoop run_loop;
+ run_loop.RunUntilIdle();
+
+ EXPECT_TRUE(callback_called_);
+ EXPECT_TRUE(base::ReadFileToString(output_file, output));
+ base::DeleteFile(temporary_dir, true);
+ }
+
+ void OnExportFinished() { callback_called_ = true; }
+
+ private:
+ base::MessageLoop message_loop_;
+ bool callback_called_;
+
+ DISALLOW_COPY_AND_ASSIGN(PasswordExporterTest);
+};
+
+TEST_F(PasswordExporterTest, CSVExport) {
+#if defined(OS_WIN)
+ const char kLineEnding[] = "\r\n";
+#else
+ const char kLineEnding[] = "\n";
+#endif
+ std::string kExpectedCSVOutput = base::StringPrintf(
+ "name,url,username,password%s"
+ "accounts.google.com,http://accounts.google.com/a/"
+ "LoginAuth,test@gmail.com,test1%s",
+ kLineEnding, kLineEnding);
+
+ std::string output;
+ ASSERT_NO_FATAL_FAILURE(StartExportAndWaitUntilCompleteThenReadOutput(
+ FILE_PATH_LITERAL(".csv"), ConstructTestPasswordForms(), &output));
+ EXPECT_EQ(kExpectedCSVOutput, output);
+}
+
+} // namespace password_manager

Powered by Google App Engine
This is Rietveld 408576698