| OLD | NEW |
| 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/message_loop.h" | 5 #include "base/message_loop.h" |
| 6 #include "chrome/browser/extensions/api/identity/experimental_web_auth_flow.h" | 6 #include "chrome/browser/extensions/api/identity/experimental_web_auth_flow.h" |
| 7 #include "chrome/browser/ui/host_desktop.h" | 7 #include "chrome/browser/ui/host_desktop.h" |
| 8 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 8 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 9 #include "chrome/test/base/testing_profile.h" | 9 #include "chrome/test/base/testing_profile.h" |
| 10 #include "content/public/browser/browser_thread.h" | |
| 11 #include "content/public/browser/web_contents.h" | 10 #include "content/public/browser/web_contents.h" |
| 12 #include "content/public/test/test_browser_thread.h" | |
| 13 #include "content/public/test/web_contents_tester.h" | 11 #include "content/public/test/web_contents_tester.h" |
| 14 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 14 |
| 17 using content::BrowserThread; | |
| 18 using content::TestBrowserThread; | |
| 19 using content::WebContents; | 15 using content::WebContents; |
| 20 using content::WebContentsTester; | 16 using content::WebContentsTester; |
| 21 using extensions::ExperimentalWebAuthFlow; | 17 using extensions::ExperimentalWebAuthFlow; |
| 22 using testing::Return; | 18 using testing::Return; |
| 23 using testing::ReturnRef; | 19 using testing::ReturnRef; |
| 24 | 20 |
| 25 namespace { | 21 namespace { |
| 26 | 22 |
| 27 class MockDelegate : public ExperimentalWebAuthFlow::Delegate { | 23 class MockDelegate : public ExperimentalWebAuthFlow::Delegate { |
| 28 public: | 24 public: |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 private: | 69 private: |
| 74 Profile* profile_; | 70 Profile* profile_; |
| 75 WebContents* web_contents_; | 71 WebContents* web_contents_; |
| 76 bool window_shown_; | 72 bool window_shown_; |
| 77 }; | 73 }; |
| 78 | 74 |
| 79 } // namespace | 75 } // namespace |
| 80 | 76 |
| 81 class ExperimentalWebAuthFlowTest : public ChromeRenderViewHostTestHarness { | 77 class ExperimentalWebAuthFlowTest : public ChromeRenderViewHostTestHarness { |
| 82 protected: | 78 protected: |
| 83 ExperimentalWebAuthFlowTest() | |
| 84 : thread_(BrowserThread::UI, &message_loop_) { | |
| 85 } | |
| 86 | |
| 87 virtual void SetUp() { | |
| 88 ChromeRenderViewHostTestHarness::SetUp(); | |
| 89 } | |
| 90 | |
| 91 virtual void TearDown() { | 79 virtual void TearDown() { |
| 92 // DetachDelegateAndDelete posts a task to clean up |flow_|, so it | 80 // DetachDelegateAndDelete posts a task to clean up |flow_|, so it |
| 93 // has to be called before | 81 // has to be called before |
| 94 // ChromeRenderViewHostTestHarness::TearDown(). | 82 // ChromeRenderViewHostTestHarness::TearDown(). |
| 95 flow_.release()->DetachDelegateAndDelete(); | 83 flow_.release()->DetachDelegateAndDelete(); |
| 96 ChromeRenderViewHostTestHarness::TearDown(); | 84 ChromeRenderViewHostTestHarness::TearDown(); |
| 97 } | 85 } |
| 98 | 86 |
| 99 void CreateAuthFlow(const GURL& url, | 87 void CreateAuthFlow(const GURL& url, |
| 100 bool interactive) { | 88 bool interactive) { |
| 101 flow_.reset(new MockExperimentalWebAuthFlow( | 89 flow_.reset(new MockExperimentalWebAuthFlow( |
| 102 &delegate_, profile(), url, interactive)); | 90 &delegate_, profile(), url, interactive)); |
| 103 } | 91 } |
| 104 | 92 |
| 105 ExperimentalWebAuthFlow* flow_base() { | 93 ExperimentalWebAuthFlow* flow_base() { |
| 106 return flow_.get(); | 94 return flow_.get(); |
| 107 } | 95 } |
| 108 | 96 |
| 109 void CallBeforeUrlLoaded(const GURL& url) { | 97 void CallBeforeUrlLoaded(const GURL& url) { |
| 110 flow_base()->BeforeUrlLoaded(url); | 98 flow_base()->BeforeUrlLoaded(url); |
| 111 } | 99 } |
| 112 | 100 |
| 113 void CallAfterUrlLoaded() { | 101 void CallAfterUrlLoaded() { |
| 114 flow_base()->AfterUrlLoaded(); | 102 flow_base()->AfterUrlLoaded(); |
| 115 } | 103 } |
| 116 | 104 |
| 117 TestBrowserThread thread_; | |
| 118 MockDelegate delegate_; | 105 MockDelegate delegate_; |
| 119 scoped_ptr<MockExperimentalWebAuthFlow> flow_; | 106 scoped_ptr<MockExperimentalWebAuthFlow> flow_; |
| 120 }; | 107 }; |
| 121 | 108 |
| 122 TEST_F(ExperimentalWebAuthFlowTest, | 109 TEST_F(ExperimentalWebAuthFlowTest, |
| 123 SilentRedirectToChromiumAppUrlNonInteractive) { | 110 SilentRedirectToChromiumAppUrlNonInteractive) { |
| 124 GURL url("https://accounts.google.com/o/oauth2/auth"); | 111 GURL url("https://accounts.google.com/o/oauth2/auth"); |
| 125 GURL result("https://abcdefghij.chromiumapp.org/google_cb"); | 112 GURL result("https://abcdefghij.chromiumapp.org/google_cb"); |
| 126 | 113 |
| 127 CreateAuthFlow(url, false); | 114 CreateAuthFlow(url, false); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 | 166 |
| 180 CreateAuthFlow(url, true); | 167 CreateAuthFlow(url, true); |
| 181 EXPECT_CALL(delegate_, | 168 EXPECT_CALL(delegate_, |
| 182 OnAuthFlowFailure(ExperimentalWebAuthFlow::WINDOW_CLOSED)) | 169 OnAuthFlowFailure(ExperimentalWebAuthFlow::WINDOW_CLOSED)) |
| 183 .Times(1); | 170 .Times(1); |
| 184 flow_->Start(); | 171 flow_->Start(); |
| 185 CallAfterUrlLoaded(); | 172 CallAfterUrlLoaded(); |
| 186 EXPECT_TRUE(flow_->HasWindow()); | 173 EXPECT_TRUE(flow_->HasWindow()); |
| 187 flow_->DestroyWebContents(); | 174 flow_->DestroyWebContents(); |
| 188 } | 175 } |
| OLD | NEW |