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

Side by Side Diff: chrome/browser/extensions/api/identity/identity_apitest.cc

Issue 11186036: Implement size and position support for launchWebAuthFlow. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix unit tests Created 8 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 | Annotate | Revision Log
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 "base/string_util.h" 5 #include "base/string_util.h"
6 #include "base/stringprintf.h"
6 #include "base/values.h" 7 #include "base/values.h"
7 #include "chrome/browser/extensions/api/identity/identity_api.h" 8 #include "chrome/browser/extensions/api/identity/identity_api.h"
8 #include "chrome/browser/extensions/api/identity/web_auth_flow.h" 9 #include "chrome/browser/extensions/api/identity/web_auth_flow.h"
9 #include "chrome/browser/extensions/extension_apitest.h" 10 #include "chrome/browser/extensions/extension_apitest.h"
10 #include "chrome/browser/extensions/extension_browsertest.h" 11 #include "chrome/browser/extensions/extension_browsertest.h"
11 #include "chrome/browser/extensions/extension_function_test_utils.h" 12 #include "chrome/browser/extensions/extension_function_test_utils.h"
13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/browser_window.h"
12 #include "chrome/browser/ui/webui/signin/login_ui_service.h" 15 #include "chrome/browser/ui/webui/signin/login_ui_service.h"
13 #include "chrome/common/chrome_switches.h" 16 #include "chrome/common/chrome_switches.h"
17 #include "chrome/common/chrome_notification_types.h"
14 #include "chrome/test/base/in_process_browser_test.h" 18 #include "chrome/test/base/in_process_browser_test.h"
19 #include "content/public/browser/notification_service.h"
20 #include "content/public/browser/notification_source.h"
21 #include "content/public/test/test_utils.h"
15 #include "google_apis/gaia/google_service_auth_error.h" 22 #include "google_apis/gaia/google_service_auth_error.h"
16 #include "google_apis/gaia/oauth2_mint_token_flow.h" 23 #include "google_apis/gaia/oauth2_mint_token_flow.h"
17 #include "googleurl/src/gurl.h" 24 #include "googleurl/src/gurl.h"
18 #include "testing/gmock/include/gmock/gmock.h" 25 #include "testing/gmock/include/gmock/gmock.h"
19 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
20 27
21 using extensions::Extension; 28 using extensions::Extension;
22 using extensions::IdentityGetAuthTokenFunction; 29 using extensions::IdentityGetAuthTokenFunction;
30 using extensions::IdentityLaunchWebAuthFlowFunction;
23 using testing::_; 31 using testing::_;
24 using testing::Return; 32 using testing::Return;
25 using testing::ReturnRef; 33 using testing::ReturnRef;
26 34
27 namespace errors = extensions::identity_constants; 35 namespace errors = extensions::identity_constants;
28 namespace utils = extension_function_test_utils; 36 namespace utils = extension_function_test_utils;
29 37
30 namespace { 38 namespace {
31 39
32 static const char kAccessToken[] = "auth_token"; 40 static const char kAccessToken[] = "auth_token";
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 390
383 func->set_install_ui_result(true); 391 func->set_install_ui_result(true);
384 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( 392 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult(
385 func.get(), "[{\"interactive\": true}]", browser())); 393 func.get(), "[{\"interactive\": true}]", browser()));
386 std::string access_token; 394 std::string access_token;
387 EXPECT_TRUE(value->GetAsString(&access_token)); 395 EXPECT_TRUE(value->GetAsString(&access_token));
388 EXPECT_EQ(std::string(kAccessToken), access_token); 396 EXPECT_EQ(std::string(kAccessToken), access_token);
389 EXPECT_FALSE(func->login_ui_shown()); 397 EXPECT_FALSE(func->login_ui_shown());
390 EXPECT_TRUE(func->install_ui_shown()); 398 EXPECT_TRUE(func->install_ui_shown());
391 } 399 }
400
401 class LaunchWebAuthFlowFunctionTest : public ExtensionBrowserTest {
402 protected:
403 void RunAndCheckBounds(
404 const std::string& extra_params,
405 int expected_x,
406 int expected_y,
407 int expected_width,
408 int expected_height) {
409 content::WindowedNotificationObserver observer(
410 chrome::NOTIFICATION_BROWSER_WINDOW_READY,
411 content::NotificationService::AllSources());
412
413 scoped_refptr<IdentityLaunchWebAuthFlowFunction> function(
414 new IdentityLaunchWebAuthFlowFunction());
415 scoped_refptr<extensions::Extension> empty_extension(
416 utils::CreateEmptyExtension());
417 function->set_extension(empty_extension.get());
418 std::string args = base::StringPrintf(
419 "[{\"interactive\": true, \"url\": \"data:text/html,auth\"%s%s}]",
420 extra_params.length() ? "," : "",
421 extra_params.c_str());
422 scoped_ptr<base::ListValue> parsed_args(utils::ParseList(args));
423 EXPECT_TRUE(parsed_args.get()) <<
424 "Could not parse extension function arguments: " << args;
425 function->SetArgs(parsed_args.get());
426 function->set_profile(browser()->profile());
427
428 // We don't use util::RunFunction because that waits until the function
429 // responds, but we want to check the size of the created browser as soon as
430 // it's created, even though there's no actual redirect to an auth URL.
431 function->Run();
432
433 observer.Wait();
434
435 Browser* web_auth_flow_browser =
436 content::Source<Browser>(observer.source()).ptr();
437 EXPECT_EQ(expected_x, web_auth_flow_browser->override_bounds().x());
438 EXPECT_EQ(expected_y, web_auth_flow_browser->override_bounds().y());
439 EXPECT_EQ(expected_width, web_auth_flow_browser->override_bounds().width());
440 EXPECT_EQ(
441 expected_height, web_auth_flow_browser->override_bounds().height());
442
443 web_auth_flow_browser->window()->Close();
444 }
445 };
446
447 IN_PROC_BROWSER_TEST_F(LaunchWebAuthFlowFunctionTest, Bounds) {
448 RunAndCheckBounds("", 0, 0, 0, 0);
449 RunAndCheckBounds("\"width\": 100, \"height\": 200", 0, 0, 100, 200);
450 RunAndCheckBounds("\"left\": 100, \"top\": 200", 100, 200, 0, 0);
451 RunAndCheckBounds(
452 "\"left\": 100, \"top\": 200, \"width\": 300, \"height\": 400",
453 100, 200, 300, 400);
454 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/identity/identity_api.cc ('k') | chrome/browser/extensions/api/identity/web_auth_flow.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698