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

Unified Diff: components/web_restrictions/browser/web_restrictions_client_unittest.cc

Issue 1890203002: Implement Web Restrictions in WebView. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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 side-by-side diff with in-line comments
Download patch
Index: components/web_restrictions/browser/web_restrictions_client_unittest.cc
diff --git a/components/web_restrictions/browser/web_restrictions_client_unittest.cc b/components/web_restrictions/browser/web_restrictions_client_unittest.cc
index df9782c42feb6607e4ef78344467e51e7a20c61a..49a811b13386d54c4e514d12881a5e3cc9e149a1 100644
--- a/components/web_restrictions/browser/web_restrictions_client_unittest.cc
+++ b/components/web_restrictions/browser/web_restrictions_client_unittest.cc
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <memory>
+
#include "base/bind.h"
#include "base/run_loop.h"
#include "components/web_restrictions/browser/mock_web_restrictions_client.h"
@@ -10,6 +12,7 @@
#include "testing/gtest/include/gtest/gtest.h"
using web_restrictions::WebRestrictionsClient;
+using web_restrictions::WebRestrictionsClientResult;
using web_restrictions::MockWebRestrictionsClient;
namespace {
@@ -39,29 +42,28 @@ TEST_F(WebRestrictionsClientTest, ShouldProceed) {
{
g_returned_result = false;
base::RunLoop run_loop;
- EXPECT_EQ(web_restrictions::PENDING,
+ ASSERT_EQ(web_restrictions::PENDING,
client_.ShouldProceed(
- true, GURL("http://example.com"),
+ true, "http://example.com",
base::Bind(&ResultCallback, run_loop.QuitClosure())));
run_loop.Run();
EXPECT_TRUE(g_returned_result);
- EXPECT_EQ(1, client_.GetResultColumnCount(GURL("http://example.com")));
}
// A repeated call should go to the cache and return a result immediately.
{
base::RunLoop run_loop;
- EXPECT_EQ(web_restrictions::ALLOW,
+ ASSERT_EQ(web_restrictions::ALLOW,
client_.ShouldProceed(
- true, GURL("http://example.com"),
+ true, "http://example.com",
base::Bind(&ResultCallback, run_loop.QuitClosure())));
}
// However a different url should miss the cache
{
g_returned_result = false;
base::RunLoop run_loop;
- EXPECT_EQ(web_restrictions::PENDING,
+ ASSERT_EQ(web_restrictions::PENDING,
client_.ShouldProceed(
- true, GURL("http://example.com/2"),
+ true, "http://example.com/2",
base::Bind(&ResultCallback, run_loop.QuitClosure())));
run_loop.Run();
EXPECT_TRUE(g_returned_result);
@@ -71,9 +73,9 @@ TEST_F(WebRestrictionsClientTest, ShouldProceed) {
client_.SetAuthority("Good2");
g_returned_result = false;
base::RunLoop run_loop;
- EXPECT_EQ(web_restrictions::PENDING,
+ ASSERT_EQ(web_restrictions::PENDING,
client_.ShouldProceed(
- true, GURL("http://example.com/2"),
+ true, "http://example.com/2",
base::Bind(&ResultCallback, run_loop.QuitClosure())));
run_loop.Run();
EXPECT_TRUE(g_returned_result);
@@ -83,38 +85,37 @@ TEST_F(WebRestrictionsClientTest, ShouldProceed) {
client_.SetAuthority("Bad");
g_returned_result = true;
base::RunLoop run_loop;
- EXPECT_EQ(web_restrictions::PENDING,
+ ASSERT_EQ(web_restrictions::PENDING,
client_.ShouldProceed(
- true, GURL("http://example.com/2"),
+ true, "http://example.com/2",
base::Bind(&ResultCallback, run_loop.QuitClosure())));
run_loop.Run();
EXPECT_FALSE(g_returned_result);
- EXPECT_EQ(3, client_.GetResultColumnCount(GURL("http://example.com/2")));
- EXPECT_EQ(42, client_.GetResultIntValue(GURL("http://example.com/2"), 1));
- EXPECT_EQ("Error string",
- client_.GetResultColumnName(GURL("http://example.com/2"), 2));
- EXPECT_EQ("http://example.com/2",
- client_.GetResultStringValue(GURL("http://example.com/2"), 2));
+ std::unique_ptr<const WebRestrictionsClientResult> result =
+ client_.GetCachedWebRestrictionsResult("http://example.com/2");
+ ASSERT_NE(nullptr, result.get());
+ EXPECT_EQ(42, result->GetInt(1));
+ EXPECT_EQ("http://example.com/2", result->GetString(2));
}
}
TEST_F(WebRestrictionsClientTest, RequestPermission) {
- client_.SetAuthority("Good");
{
+ client_.SetAuthority("Good");
base::RunLoop run_loop;
g_returned_result = false;
client_.RequestPermission(
- GURL("http://example.com"),
+ "http://example.com",
base::Bind(&ResultCallback, run_loop.QuitClosure()));
run_loop.Run();
EXPECT_TRUE(g_returned_result);
- client_.SetAuthority("Bad");
}
{
+ client_.SetAuthority("Bad");
base::RunLoop run_loop;
g_returned_result = true;
client_.RequestPermission(
- GURL("http://example.com"),
+ "http://example.com",
base::Bind(&ResultCallback, run_loop.QuitClosure()));
run_loop.Run();
EXPECT_FALSE(g_returned_result);

Powered by Google App Engine
This is Rietveld 408576698