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

Side by Side Diff: google_apis/google_api_keys_unittest.cc

Issue 2786033002: Expose way to set google api key through CWVWebView class method. (Closed)
Patch Set: fix dependency Created 3 years, 8 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
« no previous file with comments | « google_apis/google_api_keys.cc ('k') | ios/web_view/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // Unit tests for implementation of google_api_keys namespace. 5 // Unit tests for implementation of google_api_keys namespace.
6 // 6 //
7 // Because the file deals with a lot of preprocessor defines and 7 // Because the file deals with a lot of preprocessor defines and
8 // optionally includes an internal header, the way we test is by 8 // optionally includes an internal header, the way we test is by
9 // including the .cc file multiple times with different defines set. 9 // including the .cc file multiple times with different defines set.
10 // This is a little unorthodox, but it lets us test the behavior as 10 // This is a little unorthodox, but it lets us test the behavior as
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 EXPECT_EQ("env-ID_MAIN", id_main); 474 EXPECT_EQ("env-ID_MAIN", id_main);
475 EXPECT_EQ("env-SECRET_MAIN", secret_main); 475 EXPECT_EQ("env-SECRET_MAIN", secret_main);
476 EXPECT_EQ("env-ID_CLOUD_PRINT", id_cloud_print); 476 EXPECT_EQ("env-ID_CLOUD_PRINT", id_cloud_print);
477 EXPECT_EQ("env-SECRET_CLOUD_PRINT", secret_cloud_print); 477 EXPECT_EQ("env-SECRET_CLOUD_PRINT", secret_cloud_print);
478 EXPECT_EQ("env-ID_REMOTING", id_remoting); 478 EXPECT_EQ("env-ID_REMOTING", id_remoting);
479 EXPECT_EQ("env-SECRET_REMOTING", secret_remoting); 479 EXPECT_EQ("env-SECRET_REMOTING", secret_remoting);
480 EXPECT_EQ("env-ID_REMOTING_HOST", id_remoting_host); 480 EXPECT_EQ("env-ID_REMOTING_HOST", id_remoting_host);
481 EXPECT_EQ("env-SECRET_REMOTING_HOST", secret_remoting_host); 481 EXPECT_EQ("env-SECRET_REMOTING_HOST", secret_remoting_host);
482 } 482 }
483 483
484 #if defined(OS_IOS)
485 // Override all keys using both preprocessor defines and setters.
486 // Setters should win.
487 namespace override_all_keys_setters {
488
489 // We start every test by creating a clean environment for the
490 // preprocessor defines used in google_api_keys.cc
491 #undef DUMMY_API_TOKEN
492 #undef GOOGLE_API_KEY
493 #undef GOOGLE_CLIENT_ID_MAIN
494 #undef GOOGLE_CLIENT_SECRET_MAIN
495 #undef GOOGLE_CLIENT_ID_CLOUD_PRINT
496 #undef GOOGLE_CLIENT_SECRET_CLOUD_PRINT
497 #undef GOOGLE_CLIENT_ID_REMOTING
498 #undef GOOGLE_CLIENT_SECRET_REMOTING
499 #undef GOOGLE_CLIENT_ID_REMOTING_HOST
500 #undef GOOGLE_CLIENT_SECRET_REMOTING_HOST
501 #undef GOOGLE_DEFAULT_CLIENT_ID
502 #undef GOOGLE_DEFAULT_CLIENT_SECRET
503
504 #define GOOGLE_API_KEY "API_KEY"
505 #define GOOGLE_CLIENT_ID_MAIN "ID_MAIN"
506 #define GOOGLE_CLIENT_SECRET_MAIN "SECRET_MAIN"
507 #define GOOGLE_CLIENT_ID_CLOUD_PRINT "ID_CLOUD_PRINT"
508 #define GOOGLE_CLIENT_SECRET_CLOUD_PRINT "SECRET_CLOUD_PRINT"
509 #define GOOGLE_CLIENT_ID_REMOTING "ID_REMOTING"
510 #define GOOGLE_CLIENT_SECRET_REMOTING "SECRET_REMOTING"
511 #define GOOGLE_CLIENT_ID_REMOTING_HOST "ID_REMOTING_HOST"
512 #define GOOGLE_CLIENT_SECRET_REMOTING_HOST "SECRET_REMOTING_HOST"
513
514 // Undef include guard so things get defined again, within this namespace.
515 #undef GOOGLE_APIS_GOOGLE_API_KEYS_H_
516 #undef GOOGLE_APIS_INTERNAL_GOOGLE_CHROME_API_KEYS_
517 #include "google_apis/google_api_keys.cc"
518
519 } // namespace override_all_keys_setters
520
521 TEST_F(GoogleAPIKeysTest, OverrideAllKeysUsingSetters) {
522 namespace testcase = override_all_keys_setters::google_apis;
523
524 std::string api_key("setter-API_KEY");
525 testcase::SetAPIKey(api_key);
526
527 std::string id_main("setter-ID_MAIN");
528 std::string secret_main("setter-SECRET_MAIN");
529 testcase::SetOAuth2ClientID(testcase::CLIENT_MAIN, id_main);
530 testcase::SetOAuth2ClientSecret(testcase::CLIENT_MAIN, secret_main);
531
532 std::string id_cloud_print("setter-ID_CLOUD_PRINT");
533 std::string secret_cloud_print("setter-SECRET_CLOUD_PRINT");
534 testcase::SetOAuth2ClientID(testcase::CLIENT_CLOUD_PRINT, id_cloud_print);
535 testcase::SetOAuth2ClientSecret(testcase::CLIENT_CLOUD_PRINT,
536 secret_cloud_print);
537
538 std::string id_remoting("setter-ID_REMOTING");
539 std::string secret_remoting("setter-SECRET_REMOTING");
540 testcase::SetOAuth2ClientID(testcase::CLIENT_REMOTING, id_remoting);
541 testcase::SetOAuth2ClientSecret(testcase::CLIENT_REMOTING, secret_remoting);
542
543 std::string id_remoting_host("setter-ID_REMOTING_HOST");
544 std::string secret_remoting_host("setter-SECRET_REMOTING_HOST");
545 testcase::SetOAuth2ClientID(testcase::CLIENT_REMOTING_HOST, id_remoting_host);
546 testcase::SetOAuth2ClientSecret(testcase::CLIENT_REMOTING_HOST,
547 secret_remoting_host);
548
549 EXPECT_TRUE(testcase::HasKeysConfigured());
550
551 EXPECT_EQ(api_key, testcase::GetAPIKey());
552
553 EXPECT_EQ(id_main, testcase::GetOAuth2ClientID(testcase::CLIENT_MAIN));
554 EXPECT_EQ(secret_main,
555 testcase::GetOAuth2ClientSecret(testcase::CLIENT_MAIN));
556
557 EXPECT_EQ(id_cloud_print,
558 testcase::GetOAuth2ClientID(testcase::CLIENT_CLOUD_PRINT));
559 EXPECT_EQ(secret_cloud_print,
560 testcase::GetOAuth2ClientSecret(testcase::CLIENT_CLOUD_PRINT));
561
562 EXPECT_EQ(id_remoting,
563 testcase::GetOAuth2ClientID(testcase::CLIENT_REMOTING));
564 EXPECT_EQ(secret_remoting,
565 testcase::GetOAuth2ClientSecret(testcase::CLIENT_REMOTING));
566
567 EXPECT_EQ(id_remoting_host,
568 testcase::GetOAuth2ClientID(testcase::CLIENT_REMOTING_HOST));
569 EXPECT_EQ(secret_remoting_host,
570 testcase::GetOAuth2ClientSecret(testcase::CLIENT_REMOTING_HOST));
571 }
572 #endif // defined(OS_IOS)
573
484 #endif // defined(OS_LINUX) || defined(OS_MACOSX) 574 #endif // defined(OS_LINUX) || defined(OS_MACOSX)
OLDNEW
« no previous file with comments | « google_apis/google_api_keys.cc ('k') | ios/web_view/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698