| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 from common.chrome_proxy_shared_page_state import ChromeProxySharedPageState | 5 from common.chrome_proxy_shared_page_state import ChromeProxySharedPageState |
| 6 from telemetry.page import page as page_module | 6 from telemetry.page import page as page_module |
| 7 from telemetry import story | 7 from telemetry import story |
| 8 | 8 |
| 9 | 9 |
| 10 class BlockOncePage(page_module.Page): | 10 class BlockOncePage(page_module.Page): |
| 11 | 11 |
| 12 def __init__(self, url, page_set): | 12 def __init__(self, url, page_set): |
| 13 super(BlockOncePage, self).__init__(url=url,page_set=page_set, | 13 super(BlockOncePage, self).__init__(url=url,page_set=page_set, |
| 14 shared_page_state_class=ChromeProxySharedPageState) | 14 shared_page_state_class=ChromeProxySharedPageState) |
| 15 | 15 |
| 16 def RunNavigateSteps(self, action_runner): | 16 def RunNavigateSteps(self, action_runner): |
| 17 super(BlockOncePage, self).RunNavigateSteps(action_runner) | 17 super(BlockOncePage, self).RunNavigateSteps(action_runner) |
| 18 # Test block-once on a POST request. | 18 # Test block-once on a POST request. |
| 19 # Ensure that a subsequent request uses the data reduction proxy. | 19 # Ensure that a subsequent request uses the data reduction proxy. |
| 20 action_runner.ExecuteJavaScript(''' | 20 action_runner.ExecuteJavaScript2(''' |
| 21 (function() { | 21 (function() { |
| 22 window.post_request_completed = false; | 22 window.post_request_completed = false; |
| 23 var request = new XMLHttpRequest(); | 23 var request = new XMLHttpRequest(); |
| 24 request.open("POST", | 24 request.open("POST", |
| 25 "http://chromeproxy-test.appspot.com/default?" + | 25 "http://chromeproxy-test.appspot.com/default?" + |
| 26 "respBody=T0s=&respHeader=eyJBY2Nlc3MtQ29udHJvbC1BbGxvdy1Pcml" + | 26 "respBody=T0s=&respHeader=eyJBY2Nlc3MtQ29udHJvbC1BbGxvdy1Pcml" + |
| 27 "naW4iOlsiKiJdfQ==&respStatus=200&flywheelAction=block-once"); | 27 "naW4iOlsiKiJdfQ==&respStatus=200&flywheelAction=block-once"); |
| 28 request.onload = function() { | 28 request.onload = function() { |
| 29 window.post_request_completed = true; | 29 window.post_request_completed = true; |
| 30 var viaProxyRequest = new XMLHttpRequest(); | 30 var viaProxyRequest = new XMLHttpRequest(); |
| 31 viaProxyRequest.open("GET", | 31 viaProxyRequest.open("GET", |
| 32 "http://check.googlezip.net/image.png"); | 32 "http://check.googlezip.net/image.png"); |
| 33 viaProxyRequest.send(); | 33 viaProxyRequest.send(); |
| 34 }; | 34 }; |
| 35 request.send(); | 35 request.send(); |
| 36 })(); | 36 })(); |
| 37 ''') | 37 ''') |
| 38 action_runner.WaitForJavaScriptCondition( | 38 action_runner.WaitForJavaScriptCondition2( |
| 39 "window.post_request_completed == true", timeout_in_seconds=30) | 39 "window.post_request_completed == true", timeout=30) |
| 40 | 40 |
| 41 class BlockOnceStorySet(story.StorySet): | 41 class BlockOnceStorySet(story.StorySet): |
| 42 | 42 |
| 43 """ Chrome proxy test sites """ | 43 """ Chrome proxy test sites """ |
| 44 | 44 |
| 45 def __init__(self): | 45 def __init__(self): |
| 46 super(BlockOnceStorySet, self).__init__() | 46 super(BlockOnceStorySet, self).__init__() |
| 47 | 47 |
| 48 # Test block-once for a GET request. | 48 # Test block-once for a GET request. |
| 49 urls_list = [ | 49 urls_list = [ |
| 50 'http://check.googlezip.net/blocksingle/', | 50 'http://check.googlezip.net/blocksingle/', |
| 51 ] | 51 ] |
| 52 | 52 |
| 53 for url in urls_list: | 53 for url in urls_list: |
| 54 self.AddStory(BlockOncePage(url, self)) | 54 self.AddStory(BlockOncePage(url, self)) |
| OLD | NEW |