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

Side by Side Diff: chrome/browser/password_manager/native_backend_kwallet_x_unittest.cc

Issue 1383303002: Use kwalletd5 in KDE 5 environments (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 <algorithm> 5 #include <algorithm>
6 #include <map> 6 #include <map>
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 19 matching lines...) Expand all
30 #include "testing/gmock/include/gmock/gmock.h" 30 #include "testing/gmock/include/gmock/gmock.h"
31 #include "testing/gtest/include/gtest/gtest.h" 31 #include "testing/gtest/include/gtest/gtest.h"
32 32
33 using autofill::PasswordForm; 33 using autofill::PasswordForm;
34 using base::UTF8ToUTF16; 34 using base::UTF8ToUTF16;
35 using content::BrowserThread; 35 using content::BrowserThread;
36 using password_manager::PasswordStoreChange; 36 using password_manager::PasswordStoreChange;
37 using password_manager::PasswordStoreChangeList; 37 using password_manager::PasswordStoreChangeList;
38 using testing::_; 38 using testing::_;
39 using testing::Invoke; 39 using testing::Invoke;
40 using testing::TestWithParam;
41 using testing::Values;
40 using testing::Return; 42 using testing::Return;
41 43
42 namespace { 44 namespace {
43 45
44 // This class implements a very simple version of KWallet in memory. 46 // This class implements a very simple version of KWallet in memory.
45 // We only provide the parts we actually use; the real version has more. 47 // We only provide the parts we actually use; the real version has more.
46 class TestKWallet { 48 class TestKWallet {
47 public: 49 public:
48 typedef std::basic_string<uint8_t> Blob; // std::string is binary-safe. 50 typedef std::basic_string<uint8_t> Blob; // std::string is binary-safe.
49 51
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 139
138 } // anonymous namespace 140 } // anonymous namespace
139 141
140 // Obscure magic: we need to declare storage for this constant because we use it 142 // Obscure magic: we need to declare storage for this constant because we use it
141 // in ways that require its address in this test, but not in the actual code. 143 // in ways that require its address in this test, but not in the actual code.
142 const int NativeBackendKWallet::kInvalidKWalletHandle; 144 const int NativeBackendKWallet::kInvalidKWalletHandle;
143 145
144 // Subclass NativeBackendKWallet to promote some members to public for testing. 146 // Subclass NativeBackendKWallet to promote some members to public for testing.
145 class NativeBackendKWalletStub : public NativeBackendKWallet { 147 class NativeBackendKWalletStub : public NativeBackendKWallet {
146 public: 148 public:
147 explicit NativeBackendKWalletStub(LocalProfileId id) 149 explicit NativeBackendKWalletStub(LocalProfileId id,
vabr (Chromium) 2015/10/06 12:51:21 Please also drop "explicit" here.
Ed Baker 2015/10/06 16:07:44 Done.
148 : NativeBackendKWallet(id) { 150 base::nix::DesktopEnvironment desktop_env)
151 : NativeBackendKWallet(id, desktop_env) {
149 } 152 }
150 using NativeBackendKWallet::InitWithBus; 153 using NativeBackendKWallet::InitWithBus;
151 using NativeBackendKWallet::kInvalidKWalletHandle; 154 using NativeBackendKWallet::kInvalidKWalletHandle;
152 using NativeBackendKWallet::DeserializeValue; 155 using NativeBackendKWallet::DeserializeValue;
153 }; 156 };
154 157
155 // Provide some test forms to avoid having to set them up in each test. 158 // Provide some test forms to avoid having to set them up in each test.
156 class NativeBackendKWalletTestBase : public testing::Test { 159 class NativeBackendKWalletTestBase :
160 public testing::TestWithParam<base::nix::DesktopEnvironment> {
157 protected: 161 protected:
158 NativeBackendKWalletTestBase() { 162 NativeBackendKWalletTestBase() {
159 old_form_google_.origin = GURL("http://www.google.com/"); 163 old_form_google_.origin = GURL("http://www.google.com/");
160 old_form_google_.action = GURL("http://www.google.com/login"); 164 old_form_google_.action = GURL("http://www.google.com/login");
161 old_form_google_.username_element = UTF8ToUTF16("user"); 165 old_form_google_.username_element = UTF8ToUTF16("user");
162 old_form_google_.username_value = UTF8ToUTF16("joeschmoe"); 166 old_form_google_.username_value = UTF8ToUTF16("joeschmoe");
163 old_form_google_.password_element = UTF8ToUTF16("pass"); 167 old_form_google_.password_element = UTF8ToUTF16("pass");
164 old_form_google_.password_value = UTF8ToUTF16("seekrit"); 168 old_form_google_.password_value = UTF8ToUTF16("seekrit");
165 old_form_google_.submit_element = UTF8ToUTF16("submit"); 169 old_form_google_.submit_element = UTF8ToUTF16("submit");
166 old_form_google_.signon_realm = "Google"; 170 old_form_google_.signon_realm = "Google";
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 EXPECT_TRUE(result); 258 EXPECT_TRUE(result);
255 CheckPasswordChanges(*expected, *actual); 259 CheckPasswordChanges(*expected, *actual);
256 } 260 }
257 261
258 class NativeBackendKWalletTest : public NativeBackendKWalletTestBase { 262 class NativeBackendKWalletTest : public NativeBackendKWalletTestBase {
259 protected: 263 protected:
260 NativeBackendKWalletTest() 264 NativeBackendKWalletTest()
261 : ui_thread_(BrowserThread::UI, &message_loop_), 265 : ui_thread_(BrowserThread::UI, &message_loop_),
262 db_thread_(BrowserThread::DB), klauncher_ret_(0), 266 db_thread_(BrowserThread::DB), klauncher_ret_(0),
263 klauncher_contacted_(false), kwallet_runnable_(true), 267 klauncher_contacted_(false), kwallet_runnable_(true),
264 kwallet_running_(true), kwallet_enabled_(true) { 268 kwallet_running_(true), kwallet_enabled_(true),
269 desktop_env_(GetParam()) {
265 } 270 }
266 271
267 void SetUp() override; 272 void SetUp() override;
268 void TearDown() override; 273 void TearDown() override;
269 274
270 // Let the DB thread run to completion of all current tasks. 275 // Let the DB thread run to completion of all current tasks.
271 void RunDBThread() { 276 void RunDBThread() {
272 base::WaitableEvent event(false, false); 277 base::WaitableEvent event(false, false);
273 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 278 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
274 base::Bind(ThreadDone, &event)); 279 base::Bind(ThreadDone, &event));
(...skipping 30 matching lines...) Expand all
305 scoped_refptr<dbus::MockObjectProxy> mock_kwallet_proxy_; 310 scoped_refptr<dbus::MockObjectProxy> mock_kwallet_proxy_;
306 311
307 int klauncher_ret_; 312 int klauncher_ret_;
308 std::string klauncher_error_; 313 std::string klauncher_error_;
309 bool klauncher_contacted_; 314 bool klauncher_contacted_;
310 315
311 bool kwallet_runnable_; 316 bool kwallet_runnable_;
312 bool kwallet_running_; 317 bool kwallet_running_;
313 bool kwallet_enabled_; 318 bool kwallet_enabled_;
314 319
320 // Used for switching between kwalletd and kwalletd5
321 base::nix::DesktopEnvironment desktop_env_;
322
315 TestKWallet wallet_; 323 TestKWallet wallet_;
316 324
317 // For all method names contained in |failing_methods_|, the mocked KWallet 325 // For all method names contained in |failing_methods_|, the mocked KWallet
318 // will return a null response. 326 // will return a null response.
319 std::set<std::string> failing_methods_; 327 std::set<std::string> failing_methods_;
320 328
321 private: 329 private:
322 dbus::Response* KLauncherMethodCall( 330 dbus::Response* KLauncherMethodCall(
323 dbus::MethodCall* method_call, testing::Unused); 331 dbus::MethodCall* method_call, testing::Unused);
324 332
325 dbus::Response* KWalletMethodCall( 333 dbus::Response* KWalletMethodCall(
326 dbus::MethodCall* method_call, testing::Unused); 334 dbus::MethodCall* method_call, testing::Unused);
327 }; 335 };
328 336
329 void NativeBackendKWalletTest::SetUp() { 337 void NativeBackendKWalletTest::SetUp() {
330 ASSERT_TRUE(db_thread_.Start()); 338 ASSERT_TRUE(db_thread_.Start());
331 339
332 dbus::Bus::Options options; 340 dbus::Bus::Options options;
333 options.bus_type = dbus::Bus::SESSION; 341 options.bus_type = dbus::Bus::SESSION;
334 mock_session_bus_ = new dbus::MockBus(options); 342 mock_session_bus_ = new dbus::MockBus(options);
335 343
336 mock_klauncher_proxy_ = 344 mock_klauncher_proxy_ =
337 new dbus::MockObjectProxy(mock_session_bus_.get(), 345 new dbus::MockObjectProxy(mock_session_bus_.get(),
338 "org.kde.klauncher", 346 "org.kde.klauncher",
339 dbus::ObjectPath("/KLauncher")); 347 dbus::ObjectPath("/KLauncher"));
340 EXPECT_CALL(*mock_klauncher_proxy_.get(), MockCallMethodAndBlock(_, _)) 348 EXPECT_CALL(*mock_klauncher_proxy_.get(), MockCallMethodAndBlock(_, _))
341 .WillRepeatedly( 349 .WillRepeatedly(
342 Invoke(this, &NativeBackendKWalletTest::KLauncherMethodCall)); 350 Invoke(this, &NativeBackendKWalletTest::KLauncherMethodCall));
343 351
344 mock_kwallet_proxy_ = 352 if (desktop_env_ == base::nix::DESKTOP_ENVIRONMENT_KDE5) {
345 new dbus::MockObjectProxy(mock_session_bus_.get(), 353 mock_kwallet_proxy_ =
346 "org.kde.kwalletd", 354 new dbus::MockObjectProxy(mock_session_bus_.get(),
347 dbus::ObjectPath("/modules/kwalletd")); 355 "org.kde.kwalletd5",
356 dbus::ObjectPath("/modules/kwalletd5"));
357 } else {
358 mock_kwallet_proxy_ =
359 new dbus::MockObjectProxy(mock_session_bus_.get(),
360 "org.kde.kwalletd",
361 dbus::ObjectPath("/modules/kwalletd"));
362 }
348 EXPECT_CALL(*mock_kwallet_proxy_.get(), MockCallMethodAndBlock(_, _)) 363 EXPECT_CALL(*mock_kwallet_proxy_.get(), MockCallMethodAndBlock(_, _))
349 .WillRepeatedly( 364 .WillRepeatedly(
350 Invoke(this, &NativeBackendKWalletTest::KWalletMethodCall)); 365 Invoke(this, &NativeBackendKWalletTest::KWalletMethodCall));
351 366
352 EXPECT_CALL( 367 EXPECT_CALL(
353 *mock_session_bus_.get(), 368 *mock_session_bus_.get(),
354 GetObjectProxy("org.kde.klauncher", dbus::ObjectPath("/KLauncher"))) 369 GetObjectProxy("org.kde.klauncher", dbus::ObjectPath("/KLauncher")))
355 .WillRepeatedly(Return(mock_klauncher_proxy_.get())); 370 .WillRepeatedly(Return(mock_klauncher_proxy_.get()));
356 EXPECT_CALL( 371 if (desktop_env_ == base::nix::DESKTOP_ENVIRONMENT_KDE5) {
357 *mock_session_bus_.get(), 372 EXPECT_CALL(
358 GetObjectProxy("org.kde.kwalletd", dbus::ObjectPath("/modules/kwalletd"))) 373 *mock_session_bus_.get(),
359 .WillRepeatedly(Return(mock_kwallet_proxy_.get())); 374 GetObjectProxy("org.kde.kwalletd5",
375 dbus::ObjectPath("/modules/kwalletd5")))
376 .WillRepeatedly(Return(mock_kwallet_proxy_.get()));
377 } else {
378 EXPECT_CALL(
379 *mock_session_bus_.get(),
380 GetObjectProxy("org.kde.kwalletd",
381 dbus::ObjectPath("/modules/kwalletd")))
382 .WillRepeatedly(Return(mock_kwallet_proxy_.get()));
383 }
360 384
361 EXPECT_CALL(*mock_session_bus_.get(), ShutdownAndBlock()).WillOnce(Return()) 385 EXPECT_CALL(*mock_session_bus_.get(), ShutdownAndBlock()).WillOnce(Return())
362 .WillRepeatedly(Return()); 386 .WillRepeatedly(Return());
363 } 387 }
364 388
365 void NativeBackendKWalletTest::TearDown() { 389 void NativeBackendKWalletTest::TearDown() {
366 base::ThreadTaskRunnerHandle::Get()->PostTask( 390 base::ThreadTaskRunnerHandle::Get()->PostTask(
367 FROM_HERE, base::MessageLoop::QuitClosure()); 391 FROM_HERE, base::MessageLoop::QuitClosure());
368 base::MessageLoop::current()->Run(); 392 base::MessageLoop::current()->Run();
369 db_thread_.Stop(); 393 db_thread_.Stop();
370 } 394 }
371 395
372 void NativeBackendKWalletTest::TestRemoveLoginsBetween( 396 void NativeBackendKWalletTest::TestRemoveLoginsBetween(
373 RemoveBetweenMethod date_to_test) { 397 RemoveBetweenMethod date_to_test) {
374 NativeBackendKWalletStub backend(42); 398 NativeBackendKWalletStub backend(42, desktop_env_);
375 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); 399 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_));
376 400
377 form_google_.date_synced = base::Time(); 401 form_google_.date_synced = base::Time();
378 form_isc_.date_synced = base::Time(); 402 form_isc_.date_synced = base::Time();
379 form_google_.date_created = base::Time(); 403 form_google_.date_created = base::Time();
380 form_isc_.date_created = base::Time(); 404 form_isc_.date_created = base::Time();
381 base::Time now = base::Time::Now(); 405 base::Time now = base::Time::Now();
382 base::Time next_day = now + base::TimeDelta::FromDays(1); 406 base::Time next_day = now + base::TimeDelta::FromDays(1);
383 if (date_to_test == CREATED) { 407 if (date_to_test == CREATED) {
384 form_google_.date_created = now; 408 form_google_.date_created = now;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 std::vector<std::string> envs; 476 std::vector<std::string> envs;
453 std::string startup_id; 477 std::string startup_id;
454 bool blind = false; 478 bool blind = false;
455 479
456 EXPECT_TRUE(reader.PopString(&service_name)); 480 EXPECT_TRUE(reader.PopString(&service_name));
457 EXPECT_TRUE(reader.PopArrayOfStrings(&urls)); 481 EXPECT_TRUE(reader.PopArrayOfStrings(&urls));
458 EXPECT_TRUE(reader.PopArrayOfStrings(&envs)); 482 EXPECT_TRUE(reader.PopArrayOfStrings(&envs));
459 EXPECT_TRUE(reader.PopString(&startup_id)); 483 EXPECT_TRUE(reader.PopString(&startup_id));
460 EXPECT_TRUE(reader.PopBool(&blind)); 484 EXPECT_TRUE(reader.PopBool(&blind));
461 485
462 EXPECT_EQ("kwalletd", service_name); 486 if (desktop_env_ == base::nix::DESKTOP_ENVIRONMENT_KDE5)
487 EXPECT_EQ("kwalletd5", service_name);
488 else
489 EXPECT_EQ("kwalletd", service_name);
463 EXPECT_TRUE(urls.empty()); 490 EXPECT_TRUE(urls.empty());
464 EXPECT_TRUE(envs.empty()); 491 EXPECT_TRUE(envs.empty());
465 EXPECT_TRUE(startup_id.empty()); 492 EXPECT_TRUE(startup_id.empty());
466 EXPECT_FALSE(blind); 493 EXPECT_FALSE(blind);
467 494
468 if (kwallet_runnable_) 495 if (kwallet_runnable_)
469 kwallet_running_ = true; 496 kwallet_running_ = true;
470 497
471 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 498 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
472 dbus::MessageWriter writer(response.get()); 499 dbus::MessageWriter writer(response.get());
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 value.size()); 639 value.size());
613 ScopedVector<autofill::PasswordForm> forms = 640 ScopedVector<autofill::PasswordForm> forms =
614 NativeBackendKWalletStub::DeserializeValue(entries[i], pickle); 641 NativeBackendKWalletStub::DeserializeValue(entries[i], pickle);
615 const std::vector<const PasswordForm*>& expect = sorted_expected[i].second; 642 const std::vector<const PasswordForm*>& expect = sorted_expected[i].second;
616 EXPECT_EQ(expect.size(), forms.size()); 643 EXPECT_EQ(expect.size(), forms.size());
617 for (size_t j = 0; j < forms.size() && j < expect.size(); ++j) 644 for (size_t j = 0; j < forms.size() && j < expect.size(); ++j)
618 CheckPasswordForm(*expect[j], *forms[j], true); 645 CheckPasswordForm(*expect[j], *forms[j], true);
619 } 646 }
620 } 647 }
621 648
622 TEST_F(NativeBackendKWalletTest, NotEnabled) { 649 TEST_P(NativeBackendKWalletTest, NotEnabled) {
623 NativeBackendKWalletStub kwallet(42); 650 NativeBackendKWalletStub kwallet(42, desktop_env_);
624 kwallet_enabled_ = false; 651 kwallet_enabled_ = false;
625 EXPECT_FALSE(kwallet.InitWithBus(mock_session_bus_)); 652 EXPECT_FALSE(kwallet.InitWithBus(mock_session_bus_));
626 EXPECT_FALSE(klauncher_contacted_); 653 EXPECT_FALSE(klauncher_contacted_);
627 } 654 }
628 655
629 TEST_F(NativeBackendKWalletTest, NotRunnable) { 656 TEST_P(NativeBackendKWalletTest, NotRunnable) {
630 NativeBackendKWalletStub kwallet(42); 657 NativeBackendKWalletStub kwallet(42, desktop_env_);
631 kwallet_runnable_ = false; 658 kwallet_runnable_ = false;
632 kwallet_running_ = false; 659 kwallet_running_ = false;
633 EXPECT_FALSE(kwallet.InitWithBus(mock_session_bus_)); 660 EXPECT_FALSE(kwallet.InitWithBus(mock_session_bus_));
634 EXPECT_TRUE(klauncher_contacted_); 661 EXPECT_TRUE(klauncher_contacted_);
635 } 662 }
636 663
637 TEST_F(NativeBackendKWalletTest, NotRunningOrEnabled) { 664 TEST_P(NativeBackendKWalletTest, NotRunningOrEnabled) {
638 NativeBackendKWalletStub kwallet(42); 665 NativeBackendKWalletStub kwallet(42, desktop_env_);
639 kwallet_running_ = false; 666 kwallet_running_ = false;
640 kwallet_enabled_ = false; 667 kwallet_enabled_ = false;
641 EXPECT_FALSE(kwallet.InitWithBus(mock_session_bus_)); 668 EXPECT_FALSE(kwallet.InitWithBus(mock_session_bus_));
642 EXPECT_TRUE(klauncher_contacted_); 669 EXPECT_TRUE(klauncher_contacted_);
643 } 670 }
644 671
645 TEST_F(NativeBackendKWalletTest, NotRunning) { 672 TEST_P(NativeBackendKWalletTest, NotRunning) {
646 NativeBackendKWalletStub kwallet(42); 673 NativeBackendKWalletStub kwallet(42, desktop_env_);
647 kwallet_running_ = false; 674 kwallet_running_ = false;
648 EXPECT_TRUE(kwallet.InitWithBus(mock_session_bus_)); 675 EXPECT_TRUE(kwallet.InitWithBus(mock_session_bus_));
649 EXPECT_TRUE(klauncher_contacted_); 676 EXPECT_TRUE(klauncher_contacted_);
650 } 677 }
651 678
652 TEST_F(NativeBackendKWalletTest, BasicStartup) { 679 TEST_P(NativeBackendKWalletTest, BasicStartup) {
653 NativeBackendKWalletStub kwallet(42); 680 NativeBackendKWalletStub kwallet(42, desktop_env_);
654 EXPECT_TRUE(kwallet.InitWithBus(mock_session_bus_)); 681 EXPECT_TRUE(kwallet.InitWithBus(mock_session_bus_));
655 EXPECT_FALSE(klauncher_contacted_); 682 EXPECT_FALSE(klauncher_contacted_);
656 } 683 }
657 684
658 TEST_F(NativeBackendKWalletTest, BasicAddLogin) { 685 TEST_P(NativeBackendKWalletTest, BasicAddLogin) {
659 NativeBackendKWalletStub backend(42); 686 NativeBackendKWalletStub backend(42, desktop_env_);
660 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); 687 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_));
661 688
662 BrowserThread::PostTaskAndReplyWithResult( 689 BrowserThread::PostTaskAndReplyWithResult(
663 BrowserThread::DB, FROM_HERE, 690 BrowserThread::DB, FROM_HERE,
664 base::Bind(&NativeBackendKWalletStub::AddLogin, 691 base::Bind(&NativeBackendKWalletStub::AddLogin,
665 base::Unretained(&backend), form_google_), 692 base::Unretained(&backend), form_google_),
666 base::Bind(&CheckPasswordChanges, 693 base::Bind(&CheckPasswordChanges,
667 PasswordStoreChangeList(1, PasswordStoreChange( 694 PasswordStoreChangeList(1, PasswordStoreChange(
668 PasswordStoreChange::ADD, form_google_)))); 695 PasswordStoreChange::ADD, form_google_))));
669 696
670 RunDBThread(); 697 RunDBThread();
671 698
672 EXPECT_FALSE(wallet_.hasFolder("Chrome Form Data")); 699 EXPECT_FALSE(wallet_.hasFolder("Chrome Form Data"));
673 700
674 std::vector<const PasswordForm*> forms; 701 std::vector<const PasswordForm*> forms;
675 forms.push_back(&form_google_); 702 forms.push_back(&form_google_);
676 ExpectationArray expected; 703 ExpectationArray expected;
677 expected.push_back(make_pair(std::string(form_google_.signon_realm), forms)); 704 expected.push_back(make_pair(std::string(form_google_.signon_realm), forms));
678 CheckPasswordForms("Chrome Form Data (42)", expected); 705 CheckPasswordForms("Chrome Form Data (42)", expected);
679 } 706 }
680 707
681 TEST_F(NativeBackendKWalletTest, BasicUpdateLogin) { 708 TEST_P(NativeBackendKWalletTest, BasicUpdateLogin) {
682 NativeBackendKWalletStub backend(42); 709 NativeBackendKWalletStub backend(42, desktop_env_);
683 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); 710 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_));
684 711
685 BrowserThread::PostTask( 712 BrowserThread::PostTask(
686 BrowserThread::DB, FROM_HERE, 713 BrowserThread::DB, FROM_HERE,
687 base::Bind(base::IgnoreResult(&NativeBackendKWalletStub::AddLogin), 714 base::Bind(base::IgnoreResult(&NativeBackendKWalletStub::AddLogin),
688 base::Unretained(&backend), form_google_)); 715 base::Unretained(&backend), form_google_));
689 716
690 RunDBThread(); 717 RunDBThread();
691 718
692 PasswordForm new_form_google(form_google_); 719 PasswordForm new_form_google(form_google_);
(...skipping 17 matching lines...) Expand all
710 EXPECT_EQ(PasswordStoreChange::UPDATE, changes.front().type()); 737 EXPECT_EQ(PasswordStoreChange::UPDATE, changes.front().type());
711 EXPECT_EQ(new_form_google, changes.front().form()); 738 EXPECT_EQ(new_form_google, changes.front().form());
712 739
713 std::vector<const PasswordForm*> forms; 740 std::vector<const PasswordForm*> forms;
714 forms.push_back(&new_form_google); 741 forms.push_back(&new_form_google);
715 ExpectationArray expected; 742 ExpectationArray expected;
716 expected.push_back(make_pair(std::string(form_google_.signon_realm), forms)); 743 expected.push_back(make_pair(std::string(form_google_.signon_realm), forms));
717 CheckPasswordForms("Chrome Form Data (42)", expected); 744 CheckPasswordForms("Chrome Form Data (42)", expected);
718 } 745 }
719 746
720 TEST_F(NativeBackendKWalletTest, BasicListLogins) { 747 TEST_P(NativeBackendKWalletTest, BasicListLogins) {
721 NativeBackendKWalletStub backend(42); 748 NativeBackendKWalletStub backend(42, desktop_env_);
722 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); 749 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_));
723 750
724 BrowserThread::PostTask( 751 BrowserThread::PostTask(
725 BrowserThread::DB, FROM_HERE, 752 BrowserThread::DB, FROM_HERE,
726 base::Bind(base::IgnoreResult(&NativeBackendKWalletStub::AddLogin), 753 base::Bind(base::IgnoreResult(&NativeBackendKWalletStub::AddLogin),
727 base::Unretained(&backend), form_google_)); 754 base::Unretained(&backend), form_google_));
728 755
729 ScopedVector<autofill::PasswordForm> form_list; 756 ScopedVector<autofill::PasswordForm> form_list;
730 BrowserThread::PostTaskAndReplyWithResult( 757 BrowserThread::PostTaskAndReplyWithResult(
731 BrowserThread::DB, FROM_HERE, 758 BrowserThread::DB, FROM_HERE,
732 base::Bind(&NativeBackendKWalletStub::GetAutofillableLogins, 759 base::Bind(&NativeBackendKWalletStub::GetAutofillableLogins,
733 base::Unretained(&backend), &form_list), 760 base::Unretained(&backend), &form_list),
734 base::Bind(&CheckTrue)); 761 base::Bind(&CheckTrue));
735 762
736 RunDBThread(); 763 RunDBThread();
737 764
738 // Quick check that we got something back. 765 // Quick check that we got something back.
739 EXPECT_EQ(1u, form_list.size()); 766 EXPECT_EQ(1u, form_list.size());
740 767
741 EXPECT_FALSE(wallet_.hasFolder("Chrome Form Data")); 768 EXPECT_FALSE(wallet_.hasFolder("Chrome Form Data"));
742 769
743 std::vector<const PasswordForm*> forms; 770 std::vector<const PasswordForm*> forms;
744 forms.push_back(&form_google_); 771 forms.push_back(&form_google_);
745 ExpectationArray expected; 772 ExpectationArray expected;
746 expected.push_back(make_pair(std::string(form_google_.signon_realm), forms)); 773 expected.push_back(make_pair(std::string(form_google_.signon_realm), forms));
747 CheckPasswordForms("Chrome Form Data (42)", expected); 774 CheckPasswordForms("Chrome Form Data (42)", expected);
748 } 775 }
749 776
750 TEST_F(NativeBackendKWalletTest, BasicRemoveLogin) { 777 TEST_P(NativeBackendKWalletTest, BasicRemoveLogin) {
751 NativeBackendKWalletStub backend(42); 778 NativeBackendKWalletStub backend(42, desktop_env_);
752 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); 779 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_));
753 780
754 BrowserThread::PostTask( 781 BrowserThread::PostTask(
755 BrowserThread::DB, FROM_HERE, 782 BrowserThread::DB, FROM_HERE,
756 base::Bind(base::IgnoreResult(&NativeBackendKWalletStub::AddLogin), 783 base::Bind(base::IgnoreResult(&NativeBackendKWalletStub::AddLogin),
757 base::Unretained(&backend), form_google_)); 784 base::Unretained(&backend), form_google_));
758 785
759 RunDBThread(); 786 RunDBThread();
760 787
761 EXPECT_FALSE(wallet_.hasFolder("Chrome Form Data")); 788 EXPECT_FALSE(wallet_.hasFolder("Chrome Form Data"));
(...skipping 12 matching lines...) Expand all
774 base::Bind(&NativeBackendKWalletStub::RemoveLogin, 801 base::Bind(&NativeBackendKWalletStub::RemoveLogin,
775 base::Unretained(&backend), form_google_, &changes), 802 base::Unretained(&backend), form_google_, &changes),
776 base::Bind(&CheckPasswordChangesWithResult, &expected_changes, &changes)); 803 base::Bind(&CheckPasswordChangesWithResult, &expected_changes, &changes));
777 804
778 RunDBThread(); 805 RunDBThread();
779 806
780 expected.clear(); 807 expected.clear();
781 CheckPasswordForms("Chrome Form Data (42)", expected); 808 CheckPasswordForms("Chrome Form Data (42)", expected);
782 } 809 }
783 810
784 TEST_F(NativeBackendKWalletTest, UpdateNonexistentLogin) { 811 TEST_P(NativeBackendKWalletTest, UpdateNonexistentLogin) {
785 NativeBackendKWalletStub backend(42); 812 NativeBackendKWalletStub backend(42, desktop_env_);
786 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); 813 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_));
787 814
788 // First add an unrelated login. 815 // First add an unrelated login.
789 BrowserThread::PostTask( 816 BrowserThread::PostTask(
790 BrowserThread::DB, FROM_HERE, 817 BrowserThread::DB, FROM_HERE,
791 base::Bind(base::IgnoreResult(&NativeBackendKWalletStub::AddLogin), 818 base::Bind(base::IgnoreResult(&NativeBackendKWalletStub::AddLogin),
792 base::Unretained(&backend), form_google_)); 819 base::Unretained(&backend), form_google_));
793 820
794 RunDBThread(); 821 RunDBThread();
795 822
(...skipping 13 matching lines...) Expand all
809 &changes), 836 &changes),
810 base::Bind(&CheckPasswordChangesWithResult, 837 base::Bind(&CheckPasswordChangesWithResult,
811 base::Owned(new PasswordStoreChangeList), &changes)); 838 base::Owned(new PasswordStoreChangeList), &changes));
812 839
813 RunDBThread(); 840 RunDBThread();
814 841
815 EXPECT_EQ(PasswordStoreChangeList(), changes); 842 EXPECT_EQ(PasswordStoreChangeList(), changes);
816 CheckPasswordForms("Chrome Form Data (42)", expected); 843 CheckPasswordForms("Chrome Form Data (42)", expected);
817 } 844 }
818 845
819 TEST_F(NativeBackendKWalletTest, RemoveNonexistentLogin) { 846 TEST_P(NativeBackendKWalletTest, RemoveNonexistentLogin) {
820 NativeBackendKWalletStub backend(42); 847 NativeBackendKWalletStub backend(42, desktop_env_);
821 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); 848 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_));
822 849
823 // First add an unrelated login. 850 // First add an unrelated login.
824 BrowserThread::PostTask( 851 BrowserThread::PostTask(
825 BrowserThread::DB, FROM_HERE, 852 BrowserThread::DB, FROM_HERE,
826 base::Bind(base::IgnoreResult(&NativeBackendKWalletStub::AddLogin), 853 base::Bind(base::IgnoreResult(&NativeBackendKWalletStub::AddLogin),
827 base::Unretained(&backend), form_google_)); 854 base::Unretained(&backend), form_google_));
828 855
829 RunDBThread(); 856 RunDBThread();
830 857
(...skipping 23 matching lines...) Expand all
854 base::Bind(&CheckTrue)); 881 base::Bind(&CheckTrue));
855 882
856 RunDBThread(); 883 RunDBThread();
857 884
858 // Quick check that we got something back. 885 // Quick check that we got something back.
859 EXPECT_EQ(1u, form_list.size()); 886 EXPECT_EQ(1u, form_list.size());
860 887
861 CheckPasswordForms("Chrome Form Data (42)", expected); 888 CheckPasswordForms("Chrome Form Data (42)", expected);
862 } 889 }
863 890
864 TEST_F(NativeBackendKWalletTest, AddDuplicateLogin) { 891 TEST_P(NativeBackendKWalletTest, AddDuplicateLogin) {
865 NativeBackendKWalletStub backend(42); 892 NativeBackendKWalletStub backend(42, desktop_env_);
866 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); 893 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_));
867 894
868 PasswordStoreChangeList changes; 895 PasswordStoreChangeList changes;
869 changes.push_back(PasswordStoreChange(PasswordStoreChange::ADD, 896 changes.push_back(PasswordStoreChange(PasswordStoreChange::ADD,
870 form_google_)); 897 form_google_));
871 BrowserThread::PostTaskAndReplyWithResult( 898 BrowserThread::PostTaskAndReplyWithResult(
872 BrowserThread::DB, FROM_HERE, 899 BrowserThread::DB, FROM_HERE,
873 base::Bind(&NativeBackendKWalletStub::AddLogin, 900 base::Bind(&NativeBackendKWalletStub::AddLogin,
874 base::Unretained(&backend), form_google_), 901 base::Unretained(&backend), form_google_),
875 base::Bind(&NativeBackendKWalletTest::CheckPasswordChanges, 902 base::Bind(&NativeBackendKWalletTest::CheckPasswordChanges,
(...skipping 18 matching lines...) Expand all
894 921
895 EXPECT_FALSE(wallet_.hasFolder("Chrome Form Data")); 922 EXPECT_FALSE(wallet_.hasFolder("Chrome Form Data"));
896 923
897 std::vector<const PasswordForm*> forms; 924 std::vector<const PasswordForm*> forms;
898 forms.push_back(&form_google_); 925 forms.push_back(&form_google_);
899 ExpectationArray expected; 926 ExpectationArray expected;
900 expected.push_back(make_pair(std::string(form_google_.signon_realm), forms)); 927 expected.push_back(make_pair(std::string(form_google_.signon_realm), forms));
901 CheckPasswordForms("Chrome Form Data (42)", expected); 928 CheckPasswordForms("Chrome Form Data (42)", expected);
902 } 929 }
903 930
904 TEST_F(NativeBackendKWalletTest, AndroidCredentials) { 931 TEST_P(NativeBackendKWalletTest, AndroidCredentials) {
905 NativeBackendKWalletStub backend(42); 932 NativeBackendKWalletStub backend(42, desktop_env_);
906 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); 933 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_));
907 934
908 PasswordForm observed_android_form; 935 PasswordForm observed_android_form;
909 observed_android_form.scheme = PasswordForm::SCHEME_HTML; 936 observed_android_form.scheme = PasswordForm::SCHEME_HTML;
910 observed_android_form.signon_realm = 937 observed_android_form.signon_realm =
911 "android://7x7IDboo8u9YKraUsbmVkuf1-@net.rateflix.app/"; 938 "android://7x7IDboo8u9YKraUsbmVkuf1-@net.rateflix.app/";
912 PasswordForm saved_android_form = observed_android_form; 939 PasswordForm saved_android_form = observed_android_form;
913 saved_android_form.username_value = base::UTF8ToUTF16("randomusername"); 940 saved_android_form.username_value = base::UTF8ToUTF16("randomusername");
914 saved_android_form.password_value = base::UTF8ToUTF16("password"); 941 saved_android_form.password_value = base::UTF8ToUTF16("password");
915 942
(...skipping 17 matching lines...) Expand all
933 EXPECT_EQ(1u, form_list.size()); 960 EXPECT_EQ(1u, form_list.size());
934 961
935 std::vector<const PasswordForm*> forms; 962 std::vector<const PasswordForm*> forms;
936 forms.push_back(&saved_android_form); 963 forms.push_back(&saved_android_form);
937 ExpectationArray expected; 964 ExpectationArray expected;
938 expected.push_back( 965 expected.push_back(
939 make_pair(std::string(saved_android_form.signon_realm), forms)); 966 make_pair(std::string(saved_android_form.signon_realm), forms));
940 CheckPasswordForms("Chrome Form Data (42)", expected); 967 CheckPasswordForms("Chrome Form Data (42)", expected);
941 } 968 }
942 969
943 TEST_F(NativeBackendKWalletTest, RemoveLoginsCreatedBetween) { 970 TEST_P(NativeBackendKWalletTest, RemoveLoginsCreatedBetween) {
944 TestRemoveLoginsBetween(CREATED); 971 TestRemoveLoginsBetween(CREATED);
945 } 972 }
946 973
947 TEST_F(NativeBackendKWalletTest, RemoveLoginsSyncedBetween) { 974 TEST_P(NativeBackendKWalletTest, RemoveLoginsSyncedBetween) {
948 TestRemoveLoginsBetween(SYNCED); 975 TestRemoveLoginsBetween(SYNCED);
949 } 976 }
950 977
951 TEST_F(NativeBackendKWalletTest, ReadDuplicateForms) { 978 TEST_P(NativeBackendKWalletTest, ReadDuplicateForms) {
952 NativeBackendKWalletStub backend(42); 979 NativeBackendKWalletStub backend(42, desktop_env_);
953 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); 980 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_));
954 981
955 // Add 2 slightly different password forms. 982 // Add 2 slightly different password forms.
956 const char unique_string[] = "unique_unique_string"; 983 const char unique_string[] = "unique_unique_string";
957 const char unique_string_replacement[] = "uniKue_unique_string"; 984 const char unique_string_replacement[] = "uniKue_unique_string";
958 form_google_.origin = 985 form_google_.origin =
959 GURL(std::string("http://www.google.com/") + unique_string); 986 GURL(std::string("http://www.google.com/") + unique_string);
960 BrowserThread::PostTask( 987 BrowserThread::PostTask(
961 BrowserThread::DB, FROM_HERE, 988 BrowserThread::DB, FROM_HERE,
962 base::Bind(base::IgnoreResult(&NativeBackendKWalletStub::AddLogin), 989 base::Bind(base::IgnoreResult(&NativeBackendKWalletStub::AddLogin),
(...skipping 30 matching lines...) Expand all
993 EXPECT_EQ(1u, form_list.size()); 1020 EXPECT_EQ(1u, form_list.size());
994 EXPECT_EQ(form_google_, *form_list[0]); 1021 EXPECT_EQ(form_google_, *form_list[0]);
995 1022
996 std::vector<const PasswordForm*> forms; 1023 std::vector<const PasswordForm*> forms;
997 forms.push_back(&form_google_); 1024 forms.push_back(&form_google_);
998 ExpectationArray expected; 1025 ExpectationArray expected;
999 expected.push_back(make_pair(std::string(form_google_.signon_realm), forms)); 1026 expected.push_back(make_pair(std::string(form_google_.signon_realm), forms));
1000 CheckPasswordForms("Chrome Form Data (42)", expected); 1027 CheckPasswordForms("Chrome Form Data (42)", expected);
1001 } 1028 }
1002 1029
1030 // Check that if KWallet fails to respond, the backend propagates the error.
1031 TEST_P(NativeBackendKWalletTest, GetAllLoginsErrorHandling) {
1032 NativeBackendKWalletStub backend(42, desktop_env_);
1033 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_));
1034 // Make KWallet fail on calling readEntry.
1035 failing_methods_.insert("readEntry");
1036
1037 // Store some non-blacklisted logins to be potentially returned.
1038 BrowserThread::PostTaskAndReplyWithResult(
1039 BrowserThread::DB, FROM_HERE,
1040 base::Bind(&NativeBackendKWalletStub::AddLogin,
1041 base::Unretained(&backend), form_google_),
1042 base::Bind(&CheckPasswordChanges,
1043 PasswordStoreChangeList(1, PasswordStoreChange(
1044 PasswordStoreChange::ADD, form_google_))));
1045
1046 // Verify that nothing is in fact returned, because KWallet fails to respond.
1047 ScopedVector<autofill::PasswordForm> form_list;
1048 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
1049 base::Bind(&CheckGetAutofillableLoginsFails,
1050 base::Unretained(&backend), &form_list));
1051 RunDBThread();
1052 EXPECT_EQ(0u, form_list.size());
1053 }
1054
1055 INSTANTIATE_TEST_CASE_P(,
1056 NativeBackendKWalletTest,
1057 ::testing::Values(base::nix::DESKTOP_ENVIRONMENT_KDE4,
1058 base::nix::DESKTOP_ENVIRONMENT_KDE5));
1059
1003 // TODO(mdm): add more basic tests here at some point. 1060 // TODO(mdm): add more basic tests here at some point.
1004 // (For example tests for storing >1 password per realm pickle.) 1061 // (For example tests for storing >1 password per realm pickle.)
1005 1062
1006 class NativeBackendKWalletPickleTest : public NativeBackendKWalletTestBase { 1063 class NativeBackendKWalletPickleTest : public NativeBackendKWalletTestBase {
1007 protected: 1064 protected:
1008 // Based on |form|, fills |pickle| with data conforming to 1065 // Based on |form|, fills |pickle| with data conforming to
1009 // |effective_version|, but marking the pickle version as |stored_version|. In 1066 // |effective_version|, but marking the pickle version as |stored_version|. In
1010 // most cases the two versions should be the same. 1067 // most cases the two versions should be the same.
1011 void CreateVersion1PlusPickle(const PasswordForm& form, 1068 void CreateVersion1PlusPickle(const PasswordForm& form,
1012 base::Pickle* pickle, 1069 base::Pickle* pickle,
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
1189 PasswordForm form = old_form_google_; 1246 PasswordForm form = old_form_google_;
1190 form.scheme = scheme; 1247 form.scheme = scheme;
1191 CreateVersion0Pickle(size_32, form, &pickle); 1248 CreateVersion0Pickle(size_32, form, &pickle);
1192 ScopedVector<autofill::PasswordForm> form_list = 1249 ScopedVector<autofill::PasswordForm> form_list =
1193 NativeBackendKWalletStub::DeserializeValue(form.signon_realm, pickle); 1250 NativeBackendKWalletStub::DeserializeValue(form.signon_realm, pickle);
1194 EXPECT_EQ(1u, form_list.size()); 1251 EXPECT_EQ(1u, form_list.size());
1195 if (form_list.size() > 0) 1252 if (form_list.size() > 0)
1196 CheckPasswordForm(form, *form_list[0], false); 1253 CheckPasswordForm(form, *form_list[0], false);
1197 } 1254 }
1198 1255
1199 // Check that if KWallet fails to respond, the backend propagates the error.
1200 TEST_F(NativeBackendKWalletTest, GetAllLoginsErrorHandling) {
1201 NativeBackendKWalletStub backend(42);
1202 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_));
1203 // Make KWallet fail on calling readEntry.
1204 failing_methods_.insert("readEntry");
1205
1206 // Store some non-blacklisted logins to be potentially returned.
1207 BrowserThread::PostTaskAndReplyWithResult(
1208 BrowserThread::DB, FROM_HERE,
1209 base::Bind(&NativeBackendKWalletStub::AddLogin,
1210 base::Unretained(&backend), form_google_),
1211 base::Bind(&CheckPasswordChanges,
1212 PasswordStoreChangeList(1, PasswordStoreChange(
1213 PasswordStoreChange::ADD, form_google_))));
1214
1215 // Verify that nothing is in fact returned, because KWallet fails to respond.
1216 ScopedVector<autofill::PasswordForm> form_list;
1217 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
1218 base::Bind(&CheckGetAutofillableLoginsFails,
1219 base::Unretained(&backend), &form_list));
1220 RunDBThread();
1221 EXPECT_EQ(0u, form_list.size());
1222 }
1223
1224 // We try both SCHEME_HTML and SCHEME_BASIC since the scheme is stored right 1256 // We try both SCHEME_HTML and SCHEME_BASIC since the scheme is stored right
1225 // after the size in the pickle, so it's what gets read as part of the count 1257 // after the size in the pickle, so it's what gets read as part of the count
1226 // when reading 32-bit pickles on 64-bit systems. SCHEME_HTML is 0 (so we'll 1258 // when reading 32-bit pickles on 64-bit systems. SCHEME_HTML is 0 (so we'll
1227 // detect errors later) while SCHEME_BASIC is 1 (so we'll detect it then). We 1259 // detect errors later) while SCHEME_BASIC is 1 (so we'll detect it then). We
1228 // try both 32-bit and 64-bit pickles since only one will be the "other" size 1260 // try both 32-bit and 64-bit pickles since only one will be the "other" size
1229 // for whatever architecture we're running on, but we want to make sure we can 1261 // for whatever architecture we're running on, but we want to make sure we can
1230 // read all combinations in any event. 1262 // read all combinations in any event.
1231 1263
1232 TEST_F(NativeBackendKWalletPickleTest, ReadsOld32BitHTMLPickles) { 1264 TEST_F(NativeBackendKWalletPickleTest, ReadsOld32BitHTMLPickles) {
1233 CheckVersion0Pickle(true, PasswordForm::SCHEME_HTML); 1265 CheckVersion0Pickle(true, PasswordForm::SCHEME_HTML);
(...skipping 24 matching lines...) Expand all
1258 } 1290 }
1259 1291
1260 TEST_F(NativeBackendKWalletPickleTest, CheckVersion5Pickle) { 1292 TEST_F(NativeBackendKWalletPickleTest, CheckVersion5Pickle) {
1261 CheckVersion5Pickle(); 1293 CheckVersion5Pickle();
1262 } 1294 }
1263 1295
1264 TEST_F(NativeBackendKWalletPickleTest, CheckVersion6Pickle) { 1296 TEST_F(NativeBackendKWalletPickleTest, CheckVersion6Pickle) {
1265 CheckVersion6Pickle(false); 1297 CheckVersion6Pickle(false);
1266 CheckVersion6Pickle(true); 1298 CheckVersion6Pickle(true);
1267 } 1299 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698