Commit 056dcd11 authored by Marc Treib's avatar Marc Treib Committed by Commit Bot

Small cleanups in IdentityGetAccountsFunctionTest

- Use uniform initialization syntax when calling ExpectGetAccounts,
  rather than manually building an std::vector.
- Use range-based for.

Bug: none
Change-Id: I5e31970086c806791baf588ca9f382a91d0be6af
Reviewed-on: https://chromium-review.googlesource.com/1013584Reviewed-by: default avatarMihai Sardarescu <msarda@chromium.org>
Commit-Queue: Marc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#551327}
parent 8bfe1f71
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/values.h" #include "base/values.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/api/identity/identity_api.h" #include "chrome/browser/extensions/api/identity/identity_api.h"
#include "chrome/browser/extensions/api/identity/identity_constants.h" #include "chrome/browser/extensions/api/identity/identity_constants.h"
...@@ -523,59 +522,53 @@ class IdentityGetAccountsFunctionTest : public IdentityTestWithSignin { ...@@ -523,59 +522,53 @@ class IdentityGetAccountsFunctionTest : public IdentityTestWithSignin {
protected: protected:
testing::AssertionResult ExpectGetAccounts( testing::AssertionResult ExpectGetAccounts(
const std::vector<std::string>& accounts) { const std::vector<std::string>& gaia_ids) {
scoped_refptr<IdentityGetAccountsFunction> func( scoped_refptr<IdentityGetAccountsFunction> func(
new IdentityGetAccountsFunction); new IdentityGetAccountsFunction);
func->set_extension( func->set_extension(
ExtensionBuilder("Test").SetID(kExtensionId).Build().get()); ExtensionBuilder("Test").SetID(kExtensionId).Build().get());
if (!utils::RunFunction(func.get(), std::string("[]"), browser(), if (!utils::RunFunction(func.get(), std::string("[]"), browser(),
api_test_utils::NONE)) { api_test_utils::NONE)) {
return GenerateFailureResult(accounts, NULL) return GenerateFailureResult(gaia_ids, NULL)
<< "getAccounts did not return a result."; << "getAccounts did not return a result.";
} }
const base::ListValue* callback_arguments = func->GetResultList(); const base::ListValue* callback_arguments = func->GetResultList();
if (!callback_arguments) if (!callback_arguments)
return GenerateFailureResult(accounts, NULL) << "NULL result"; return GenerateFailureResult(gaia_ids, NULL) << "NULL result";
if (callback_arguments->GetSize() != 1) { if (callback_arguments->GetSize() != 1) {
return GenerateFailureResult(accounts, NULL) return GenerateFailureResult(gaia_ids, NULL)
<< "Expected 1 argument but got " << callback_arguments->GetSize(); << "Expected 1 argument but got " << callback_arguments->GetSize();
} }
const base::ListValue* results; const base::ListValue* results;
if (!callback_arguments->GetList(0, &results)) if (!callback_arguments->GetList(0, &results))
GenerateFailureResult(accounts, NULL) << "Result was not an array"; GenerateFailureResult(gaia_ids, NULL) << "Result was not an array";
std::set<std::string> result_ids; std::set<std::string> result_ids;
for (base::ListValue::const_iterator it = results->begin(); for (const base::Value& item : *results) {
it != results->end();
++it) {
std::unique_ptr<api::identity::AccountInfo> info = std::unique_ptr<api::identity::AccountInfo> info =
api::identity::AccountInfo::FromValue(*it); api::identity::AccountInfo::FromValue(item);
if (info.get()) if (info.get())
result_ids.insert(info->id); result_ids.insert(info->id);
else else
return GenerateFailureResult(accounts, results); return GenerateFailureResult(gaia_ids, results);
} }
for (std::vector<std::string>::const_iterator it = accounts.begin(); for (const std::string& gaia_id : gaia_ids) {
it != accounts.end(); if (result_ids.find(gaia_id) == result_ids.end())
++it) { return GenerateFailureResult(gaia_ids, results);
if (result_ids.find(*it) == result_ids.end())
return GenerateFailureResult(accounts, results);
} }
return testing::AssertionResult(true); return testing::AssertionResult(true);
} }
testing::AssertionResult GenerateFailureResult( testing::AssertionResult GenerateFailureResult(
const ::std::vector<std::string>& accounts, const ::std::vector<std::string>& gaia_ids,
const base::ListValue* results) { const base::ListValue* results) {
testing::Message msg("Expected: "); testing::Message msg("Expected: ");
for (std::vector<std::string>::const_iterator it = accounts.begin(); for (const std::string& gaia_id : gaia_ids) {
it != accounts.end(); msg << gaia_id << " ";
++it) {
msg << *it << " ";
} }
msg << "Actual: "; msg << "Actual: ";
if (!results) { if (!results) {
...@@ -600,12 +593,12 @@ IN_PROC_BROWSER_TEST_F(IdentityGetAccountsFunctionTest, MultiAccountOn) { ...@@ -600,12 +593,12 @@ IN_PROC_BROWSER_TEST_F(IdentityGetAccountsFunctionTest, MultiAccountOn) {
} }
IN_PROC_BROWSER_TEST_F(IdentityGetAccountsFunctionTest, NoneSignedIn) { IN_PROC_BROWSER_TEST_F(IdentityGetAccountsFunctionTest, NoneSignedIn) {
EXPECT_TRUE(ExpectGetAccounts(std::vector<std::string>())); EXPECT_TRUE(ExpectGetAccounts({}));
} }
IN_PROC_BROWSER_TEST_F(IdentityGetAccountsFunctionTest, NoPrimaryAccount) { IN_PROC_BROWSER_TEST_F(IdentityGetAccountsFunctionTest, NoPrimaryAccount) {
AddAccount("secondary@example.com"); AddAccount("secondary@example.com");
EXPECT_TRUE(ExpectGetAccounts(std::vector<std::string>())); EXPECT_TRUE(ExpectGetAccounts({}));
} }
IN_PROC_BROWSER_TEST_F(IdentityGetAccountsFunctionTest, IN_PROC_BROWSER_TEST_F(IdentityGetAccountsFunctionTest,
...@@ -616,24 +609,20 @@ IN_PROC_BROWSER_TEST_F(IdentityGetAccountsFunctionTest, ...@@ -616,24 +609,20 @@ IN_PROC_BROWSER_TEST_F(IdentityGetAccountsFunctionTest,
// AccountFetcherService::OnRefreshTokenRevoked), which triggers DCHECKs in // AccountFetcherService::OnRefreshTokenRevoked), which triggers DCHECKs in
// IdentityManager::GetPrimaryAccountInfo. // IdentityManager::GetPrimaryAccountInfo.
token_service_->RevokeCredentials(primary_account_id); token_service_->RevokeCredentials(primary_account_id);
EXPECT_TRUE(ExpectGetAccounts(std::vector<std::string>())); EXPECT_TRUE(ExpectGetAccounts({}));
} }
IN_PROC_BROWSER_TEST_F(IdentityGetAccountsFunctionTest, IN_PROC_BROWSER_TEST_F(IdentityGetAccountsFunctionTest,
PrimaryAccountSignedIn) { PrimaryAccountSignedIn) {
SignIn("primary@example.com"); SignIn("primary@example.com");
std::vector<std::string> primary; EXPECT_TRUE(ExpectGetAccounts({"gaia_id_for_primary@example.com"}));
primary.push_back("gaia_id_for_primary@example.com");
EXPECT_TRUE(ExpectGetAccounts(primary));
} }
IN_PROC_BROWSER_TEST_F(IdentityGetAccountsFunctionTest, TwoAccountsSignedIn) { IN_PROC_BROWSER_TEST_F(IdentityGetAccountsFunctionTest, TwoAccountsSignedIn) {
SignIn("primary@example.com"); SignIn("primary@example.com");
AddAccount("secondary@example.com"); AddAccount("secondary@example.com");
std::vector<std::string> two_accounts; EXPECT_TRUE(ExpectGetAccounts({"gaia_id_for_primary@example.com",
two_accounts.push_back("gaia_id_for_primary@example.com"); "gaia_id_for_secondary@example.com"}));
two_accounts.push_back("gaia_id_for_secondary@example.com");
EXPECT_TRUE(ExpectGetAccounts(two_accounts));
} }
class IdentityOldProfilesGetAccountsFunctionTest class IdentityOldProfilesGetAccountsFunctionTest
...@@ -653,9 +642,7 @@ IN_PROC_BROWSER_TEST_F(IdentityOldProfilesGetAccountsFunctionTest, ...@@ -653,9 +642,7 @@ IN_PROC_BROWSER_TEST_F(IdentityOldProfilesGetAccountsFunctionTest,
TwoAccountsSignedIn) { TwoAccountsSignedIn) {
SignIn("primary@example.com"); SignIn("primary@example.com");
AddAccount("secondary@example.com"); AddAccount("secondary@example.com");
std::vector<std::string> only_primary; EXPECT_TRUE(ExpectGetAccounts({"gaia_id_for_primary@example.com"}));
only_primary.push_back("gaia_id_for_primary@example.com");
EXPECT_TRUE(ExpectGetAccounts(only_primary));
} }
class IdentityGetProfileUserInfoFunctionTest : public IdentityTestWithSignin { class IdentityGetProfileUserInfoFunctionTest : public IdentityTestWithSignin {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment