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

Side by Side Diff: third_party/WebKit/Source/platform/testing/URLTestHelpers.cpp

Issue 2680723002: Generalize ScopedRegisteredURL as ScoedMockedURL* (Closed)
Patch Set: Created 3 years, 10 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 55
56 // filePath = basePath + ("/" +) fileName. 56 // filePath = basePath + ("/" +) fileName.
57 base::FilePath filePath = 57 base::FilePath filePath =
58 WebStringToFilePath(basePath).Append(WebStringToFilePath(fileName)); 58 WebStringToFilePath(basePath).Append(WebStringToFilePath(fileName));
59 59
60 KURL url = toKURL(fullURL); 60 KURL url = toKURL(fullURL);
61 registerMockedURLLoad(url, FilePathToWebString(filePath), mimeType); 61 registerMockedURLLoad(url, FilePathToWebString(filePath), mimeType);
62 return WebURL(url); 62 return WebURL(url);
63 } 63 }
64 64
65 void registerMockedURLLoad(const WebURL& fullURL, 65 WebURL registerMockedURLLoad(const WebURL& fullURL,
66 const WebString& filePath, 66 const WebString& filePath,
67 const WebString& mimeType) { 67 const WebString& mimeType) {
68 WebURLLoadTiming timing; 68 WebURLLoadTiming timing;
69 timing.initialize(); 69 timing.initialize();
70 70
71 WebURLResponse response(fullURL); 71 WebURLResponse response(fullURL);
72 response.setMIMEType(mimeType); 72 response.setMIMEType(mimeType);
73 response.setHTTPStatusCode(200); 73 response.setHTTPStatusCode(200);
74 response.setLoadTiming(timing); 74 response.setLoadTiming(timing);
75 75
76 registerMockedURLLoadWithCustomResponse(fullURL, filePath, response); 76 registerMockedURLLoadWithCustomResponse(fullURL, filePath, response);
77 return fullURL;
77 } 78 }
78 79
79 void registerMockedErrorURLLoad(const WebURL& fullURL) { 80 WebURL registerMockedErrorURLLoad(const WebURL& fullURL) {
80 WebURLLoadTiming timing; 81 WebURLLoadTiming timing;
81 timing.initialize(); 82 timing.initialize();
82 83
83 WebURLResponse response; 84 WebURLResponse response;
84 response.setMIMEType("image/png"); 85 response.setMIMEType("image/png");
85 response.setHTTPStatusCode(404); 86 response.setHTTPStatusCode(404);
86 response.setLoadTiming(timing); 87 response.setLoadTiming(timing);
87 88
88 WebURLError error; 89 WebURLError error;
89 error.reason = 404; 90 error.reason = 404;
90 Platform::current()->getURLLoaderMockFactory()->registerErrorURL( 91 Platform::current()->getURLLoaderMockFactory()->registerErrorURL(
91 fullURL, response, error); 92 fullURL, response, error);
93 return fullURL;
92 } 94 }
93 95
94 void registerMockedURLLoadWithCustomResponse(const WebURL& fullURL, 96 WebURL registerMockedURLLoadWithCustomResponse(const WebURL& fullURL,
95 const WebString& filePath, 97 const WebString& filePath,
96 WebURLResponse response) { 98 WebURLResponse response) {
97 Platform::current()->getURLLoaderMockFactory()->registerURL(fullURL, response, 99 Platform::current()->getURLLoaderMockFactory()->registerURL(fullURL, response,
98 filePath); 100 filePath);
101 return fullURL;
99 } 102 }
100 103
101 } // namespace URLTestHelpers 104 } // namespace URLTestHelpers
105
106 ScopedMockedURL::ScopedMockedURL(const WebURL& url) : m_url(url) {}
107
108 ScopedMockedURL::~ScopedMockedURL() {
109 Platform::current()->getURLLoaderMockFactory()->unregisterURL(m_url);
110 }
111
102 } // namespace blink 112 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698