| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/run_loop.h" | 6 #include "base/run_loop.h" |
| 7 #include "components/web_restrictions/browser/mock_web_restrictions_client.h" | 7 #include "components/web_restrictions/browser/mock_web_restrictions_client.h" |
| 8 #include "components/web_restrictions/browser/web_restrictions_client.h" | 8 #include "components/web_restrictions/browser/web_restrictions_client.h" |
| 9 #include "content/public/test/test_browser_thread_bundle.h" | 9 #include "content/public/test/test_browser_thread_bundle.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 // delayed result. | 38 // delayed result. |
| 39 { | 39 { |
| 40 g_returned_result = false; | 40 g_returned_result = false; |
| 41 base::RunLoop run_loop; | 41 base::RunLoop run_loop; |
| 42 EXPECT_EQ(web_restrictions::PENDING, | 42 EXPECT_EQ(web_restrictions::PENDING, |
| 43 client_.ShouldProceed( | 43 client_.ShouldProceed( |
| 44 true, GURL("http://example.com"), | 44 true, GURL("http://example.com"), |
| 45 base::Bind(&ResultCallback, run_loop.QuitClosure()))); | 45 base::Bind(&ResultCallback, run_loop.QuitClosure()))); |
| 46 run_loop.Run(); | 46 run_loop.Run(); |
| 47 EXPECT_TRUE(g_returned_result); | 47 EXPECT_TRUE(g_returned_result); |
| 48 EXPECT_EQ(1, client_.GetResultColumnCount(GURL("http://example.com"))); |
| 48 } | 49 } |
| 49 // A repeated call should go to the cache and return a result immediately. | 50 // A repeated call should go to the cache and return a result immediately. |
| 50 { | 51 { |
| 51 base::RunLoop run_loop; | 52 base::RunLoop run_loop; |
| 52 EXPECT_EQ(web_restrictions::ALLOW, | 53 EXPECT_EQ(web_restrictions::ALLOW, |
| 53 client_.ShouldProceed( | 54 client_.ShouldProceed( |
| 54 true, GURL("http://example.com"), | 55 true, GURL("http://example.com"), |
| 55 base::Bind(&ResultCallback, run_loop.QuitClosure()))); | 56 base::Bind(&ResultCallback, run_loop.QuitClosure()))); |
| 56 } | 57 } |
| 57 // However a different url should miss the cache | 58 // However a different url should miss the cache |
| (...skipping 23 matching lines...) Expand all Loading... |
| 81 { | 82 { |
| 82 client_.SetAuthority("Bad"); | 83 client_.SetAuthority("Bad"); |
| 83 g_returned_result = true; | 84 g_returned_result = true; |
| 84 base::RunLoop run_loop; | 85 base::RunLoop run_loop; |
| 85 EXPECT_EQ(web_restrictions::PENDING, | 86 EXPECT_EQ(web_restrictions::PENDING, |
| 86 client_.ShouldProceed( | 87 client_.ShouldProceed( |
| 87 true, GURL("http://example.com/2"), | 88 true, GURL("http://example.com/2"), |
| 88 base::Bind(&ResultCallback, run_loop.QuitClosure()))); | 89 base::Bind(&ResultCallback, run_loop.QuitClosure()))); |
| 89 run_loop.Run(); | 90 run_loop.Run(); |
| 90 EXPECT_FALSE(g_returned_result); | 91 EXPECT_FALSE(g_returned_result); |
| 91 std::string error_html; | 92 EXPECT_EQ(3, client_.GetResultColumnCount(GURL("http://example.com/2"))); |
| 92 EXPECT_TRUE( | 93 EXPECT_EQ(42, client_.GetResultIntValue(GURL("http://example.com/2"), 1)); |
| 93 client_.GetErrorHtml(GURL("http://example.com/2"), &error_html)); | 94 EXPECT_EQ("Error string", |
| 94 EXPECT_EQ("http://example.com/2", error_html); | 95 client_.GetResultColumnName(GURL("http://example.com/2"), 2)); |
| 96 EXPECT_EQ("http://example.com/2", |
| 97 client_.GetResultStringValue(GURL("http://example.com/2"), 2)); |
| 95 } | 98 } |
| 96 } | 99 } |
| 97 | 100 |
| 98 TEST_F(WebRestrictionsClientTest, RequestPermission) { | 101 TEST_F(WebRestrictionsClientTest, RequestPermission) { |
| 99 client_.SetAuthority("Good"); | 102 client_.SetAuthority("Good"); |
| 100 { | 103 { |
| 101 base::RunLoop run_loop; | 104 base::RunLoop run_loop; |
| 102 g_returned_result = false; | 105 g_returned_result = false; |
| 103 client_.RequestPermission( | 106 client_.RequestPermission( |
| 104 GURL("http://example.com"), | 107 GURL("http://example.com"), |
| 105 base::Bind(&ResultCallback, run_loop.QuitClosure())); | 108 base::Bind(&ResultCallback, run_loop.QuitClosure())); |
| 106 run_loop.Run(); | 109 run_loop.Run(); |
| 107 EXPECT_TRUE(g_returned_result); | 110 EXPECT_TRUE(g_returned_result); |
| 108 client_.SetAuthority("Bad"); | 111 client_.SetAuthority("Bad"); |
| 109 } | 112 } |
| 110 { | 113 { |
| 111 base::RunLoop run_loop; | 114 base::RunLoop run_loop; |
| 112 g_returned_result = true; | 115 g_returned_result = true; |
| 113 client_.RequestPermission( | 116 client_.RequestPermission( |
| 114 GURL("http://example.com"), | 117 GURL("http://example.com"), |
| 115 base::Bind(&ResultCallback, run_loop.QuitClosure())); | 118 base::Bind(&ResultCallback, run_loop.QuitClosure())); |
| 116 run_loop.Run(); | 119 run_loop.Run(); |
| 117 EXPECT_FALSE(g_returned_result); | 120 EXPECT_FALSE(g_returned_result); |
| 118 } | 121 } |
| 119 } | 122 } |
| OLD | NEW |