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

Unified Diff: components/password_manager/core/browser/site_affiliation/asset_link_retriever_unittest.cc

Issue 2967503003: Introduce a parse for digital asset links. (Closed)
Patch Set: Fix compilation Created 3 years, 5 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
« no previous file with comments | « components/password_manager/core/browser/site_affiliation/asset_link_retriever.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/password_manager/core/browser/site_affiliation/asset_link_retriever_unittest.cc
diff --git a/components/password_manager/core/browser/site_affiliation/asset_link_retriever_unittest.cc b/components/password_manager/core/browser/site_affiliation/asset_link_retriever_unittest.cc
index 700dbec5b77333c8291c38c41c867625b9481f10..df4fb29ecf2d364f0c4a0855b9c3966cf697cc2b 100644
--- a/components/password_manager/core/browser/site_affiliation/asset_link_retriever_unittest.cc
+++ b/components/password_manager/core/browser/site_affiliation/asset_link_retriever_unittest.cc
@@ -9,11 +9,15 @@
#include "base/test/scoped_task_environment.h"
#include "net/url_request/test_url_fetcher_factory.h"
#include "net/url_request/url_request_test_util.h"
+#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace password_manager {
namespace {
+using ::testing::IsEmpty;
+using ::testing::ElementsAre;
+
constexpr char kAssetLinkFile[] =
"https://example.com/.well-known/assetlinks.json";
@@ -98,10 +102,63 @@ TEST_F(AssetLinkRetrieverTest, LoadRedirect) {
factory().SetFakeResponse(GURL(kAssetLinkFile), std::string(),
net::HTTP_FOUND, net::URLRequestStatus::CANCELED);
asset_link_retriever->Start(request_context());
+ EXPECT_EQ(AssetLinkRetriever::State::NETWORK_REQUEST,
+ asset_link_retriever->state());
+
+ RunUntilIdle();
+ EXPECT_EQ(AssetLinkRetriever::State::FINISHED, asset_link_retriever->state());
+ EXPECT_TRUE(asset_link_retriever->error());
+}
+
+// Load a valid asset links resource.
+TEST_F(AssetLinkRetrieverTest, LoadValidFile) {
+ scoped_refptr<AssetLinkRetriever> asset_link_retriever =
+ base::MakeRefCounted<AssetLinkRetriever>(GURL(kAssetLinkFile));
+ EXPECT_EQ(AssetLinkRetriever::State::INACTIVE, asset_link_retriever->state());
+
+ constexpr char json[] =
+ u8R"([{
+ "relation": ["delegate_permission/common.get_login_creds"],
+ "target": {
+ "namespace": "web",
+ "site": "https://www.google.com"
+ }
+ },{
+ "include": "https://go/assetlinks.json"
+ }])";
+ factory().SetFakeResponse(GURL(kAssetLinkFile), json, net::HTTP_OK,
+ net::URLRequestStatus::SUCCESS);
+ asset_link_retriever->Start(request_context());
+ EXPECT_EQ(AssetLinkRetriever::State::NETWORK_REQUEST,
+ asset_link_retriever->state());
+
+ RunUntilIdle();
+ EXPECT_EQ(AssetLinkRetriever::State::FINISHED, asset_link_retriever->state());
+ EXPECT_FALSE(asset_link_retriever->error());
+ EXPECT_THAT(asset_link_retriever->includes(),
+ ElementsAre(GURL("https://go/assetlinks.json")));
+ EXPECT_THAT(asset_link_retriever->targets(),
+ ElementsAre(GURL("https://www.google.com")));
+}
+
+// Load a broken resource.
+TEST_F(AssetLinkRetrieverTest, LoadInvalidFile) {
+ scoped_refptr<AssetLinkRetriever> asset_link_retriever =
+ base::MakeRefCounted<AssetLinkRetriever>(GURL(kAssetLinkFile));
+ EXPECT_EQ(AssetLinkRetriever::State::INACTIVE, asset_link_retriever->state());
+
+ constexpr char json[] = u8R"([{111}])";
+ factory().SetFakeResponse(GURL(kAssetLinkFile), json, net::HTTP_OK,
+ net::URLRequestStatus::SUCCESS);
+ asset_link_retriever->Start(request_context());
+ EXPECT_EQ(AssetLinkRetriever::State::NETWORK_REQUEST,
+ asset_link_retriever->state());
RunUntilIdle();
EXPECT_EQ(AssetLinkRetriever::State::FINISHED, asset_link_retriever->state());
EXPECT_TRUE(asset_link_retriever->error());
+ EXPECT_THAT(asset_link_retriever->includes(), IsEmpty());
+ EXPECT_THAT(asset_link_retriever->targets(), IsEmpty());
}
} // namespace
« no previous file with comments | « components/password_manager/core/browser/site_affiliation/asset_link_retriever.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698