Skip to content

Commit

Permalink
[Offline Pages] Rename page names saved by test harness to hostnames.
Browse files Browse the repository at this point in the history
Fixed the issue where the names of the archives would be random GUIDs
after pulling down from the device. Added a renaming step in the script
which would parse the mhtml source, get the original URL and use that as
filename in order to make archive names easier to understand.

BUG=None

Review-Url: https://codereview.chromium.org/2618863002
Cr-Commit-Position: refs/heads/master@{#442704}
  • Loading branch information
romax authored and Commit bot committed Jan 10, 2017
1 parent 53b088c commit af210b9
Showing 1 changed file with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@

import argparse
import os
import re
import shutil
import subprocess
import sys
import urlparse

DEFAULT_USER_REQUEST = True
DEFAULT_USE_TEST_SCHEDULER = True
Expand Down Expand Up @@ -155,9 +157,13 @@ def get_adb_command(args):
# Also turning off the strict mode so that we won't run into StrictMode
# violations when writing to files.
test_runner_cmd = [
test_runner_path, '-f',
test_runner_path,
'-f',
'OfflinePageSavePageLaterEvaluationTest.testFailureRate',
'--timeout-scale', '20.0', '--strict-mode', 'off',
'--timeout-scale',
'20.0',
'--strict-mode',
'off',
]
if options.verbose:
test_runner_cmd += ['-v']
Expand All @@ -184,6 +190,28 @@ def get_adb_command(args):
]))
print 'Test finished!'

print 'Renaming archive files with host names.'
pattern = 'Content-Location: (.*)'
for filename in os.listdir(archive_dir):
path = os.path.join(archive_dir, filename)
with open(path) as f:
content = f.read()
result = re.search(pattern, content)
if (result == None):
continue
url = result.group(1)
url_parse = urlparse.urlparse(url)
hostname = url_parse[1].replace('.', '_')
url_path = re.sub('[^0-9a-zA-Z]+', '_', url_parse[2][1:])

if (len(hostname) == 0):
hostname = 'error_parsing_hostname'
continue
newname = hostname + '-' + url_path
newpath = os.path.join(archive_dir, newname + '.mhtml')
os.rename(path, newpath)
print 'Renaming finished.'


if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))

0 comments on commit af210b9

Please sign in to comment.