OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/macros.h" | 6 #include "base/macros.h" |
| 7 #include "chrome/browser/sync/test/integration/sync_integration_test_util.h" |
7 #include "chrome/browser/sync/test/integration/sync_test.h" | 8 #include "chrome/browser/sync/test/integration/sync_test.h" |
8 #include "chrome/browser/sync/test/integration/wifi_credentials_helper.h" | 9 #include "chrome/browser/sync/test/integration/wifi_credentials_helper.h" |
9 #include "chrome/common/chrome_switches.h" | 10 #include "chrome/common/chrome_switches.h" |
| 11 #include "components/wifi_sync/wifi_credential.h" |
| 12 #include "components/wifi_sync/wifi_security_class.h" |
| 13 |
| 14 using sync_integration_test_util::AwaitCommitActivityCompletion; |
| 15 using wifi_sync::WifiCredential; |
| 16 |
| 17 using WifiCredentialSet = wifi_sync::WifiCredential::CredentialSet; |
10 | 18 |
11 class SingleClientWifiCredentialsSyncTest : public SyncTest { | 19 class SingleClientWifiCredentialsSyncTest : public SyncTest { |
12 public: | 20 public: |
13 SingleClientWifiCredentialsSyncTest() : SyncTest(SINGLE_CLIENT) {} | 21 SingleClientWifiCredentialsSyncTest() : SyncTest(SINGLE_CLIENT) {} |
14 ~SingleClientWifiCredentialsSyncTest() override {} | 22 ~SingleClientWifiCredentialsSyncTest() override {} |
15 | 23 |
| 24 // SyncTest implementation. |
| 25 void SetUp() override { |
| 26 wifi_credentials_helper::SetUp(); |
| 27 SyncTest::SetUp(); |
| 28 } |
| 29 |
16 void SetUpCommandLine(base::CommandLine* command_line) override { | 30 void SetUpCommandLine(base::CommandLine* command_line) override { |
17 SyncTest::SetUpCommandLine(command_line); | 31 SyncTest::SetUpCommandLine(command_line); |
18 command_line->AppendSwitch(switches::kEnableWifiCredentialSync); | 32 command_line->AppendSwitch(switches::kEnableWifiCredentialSync); |
19 } | 33 } |
20 | 34 |
| 35 bool SetupClients() override { |
| 36 if (!SyncTest::SetupClients()) |
| 37 return false; |
| 38 wifi_credentials_helper::SetupClients(); |
| 39 return true; |
| 40 } |
| 41 |
21 private: | 42 private: |
22 DISALLOW_COPY_AND_ASSIGN(SingleClientWifiCredentialsSyncTest); | 43 DISALLOW_COPY_AND_ASSIGN(SingleClientWifiCredentialsSyncTest); |
23 }; | 44 }; |
24 | 45 |
25 IN_PROC_BROWSER_TEST_F(SingleClientWifiCredentialsSyncTest, NoCredentials) { | 46 IN_PROC_BROWSER_TEST_F(SingleClientWifiCredentialsSyncTest, NoCredentials) { |
26 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 47 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
27 ASSERT_TRUE(wifi_credentials_helper::VerifierIsEmpty()); | 48 ASSERT_TRUE(wifi_credentials_helper::VerifierIsEmpty()); |
28 ASSERT_TRUE(wifi_credentials_helper::ProfileMatchesVerifier(0)); | 49 ASSERT_TRUE(wifi_credentials_helper::ProfileMatchesVerifier(0)); |
29 } | 50 } |
| 51 |
| 52 IN_PROC_BROWSER_TEST_F(SingleClientWifiCredentialsSyncTest, SingleCredential) { |
| 53 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
| 54 |
| 55 const char ssid[] = "fake-ssid"; |
| 56 scoped_ptr<WifiCredential> credential = |
| 57 wifi_credentials_helper::MakeWifiCredential( |
| 58 ssid, wifi_sync::SECURITY_CLASS_PSK, "fake_passphrase"); |
| 59 ASSERT_TRUE(credential); |
| 60 |
| 61 const size_t profile_index = 0; |
| 62 wifi_credentials_helper::AddWifiCredential( |
| 63 profile_index, "fake_id", *credential); |
| 64 |
| 65 const WifiCredentialSet verifier_credentials = |
| 66 wifi_credentials_helper::GetWifiCredentialsForProfile(verifier()); |
| 67 EXPECT_EQ(1U, verifier_credentials.size()); |
| 68 EXPECT_EQ(WifiCredential::MakeSsidBytesForTest(ssid), |
| 69 verifier_credentials.begin()->ssid()); |
| 70 |
| 71 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((profile_index)))); |
| 72 EXPECT_TRUE(wifi_credentials_helper::ProfileMatchesVerifier(profile_index)); |
| 73 } |
OLD | NEW |