michael@0: #!/usr/bin/env python michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: import unittest michael@0: import sys, os michael@0: import re, glob michael@0: import difflib michael@0: michael@0: this_dir = os.path.abspath(os.path.dirname(__file__)) michael@0: data_dir = os.path.join(this_dir, 'data') michael@0: michael@0: from jssh_driver import JsshTester michael@0: michael@0: class LayoutEngineTests(unittest.TestCase): michael@0: michael@0: def setUp(self): michael@0: self.tester = JsshTester("localhost") michael@0: self.get_files_from_data_dir() michael@0: michael@0: def get_files_from_data_dir(self): michael@0: self.html_files = glob.glob("%s/*.html" % data_dir) michael@0: print self.html_files michael@0: self.golden_images = [re.sub("\.html$", "_inner_html.txt", filename) for filename in self.html_files] michael@0: print self.golden_images michael@0: michael@0: def test_inner_html(self): michael@0: self.failUnless(len(self.html_files) == len(self.golden_images)) michael@0: failures = 0 michael@0: for file, golden_image in zip(self.html_files, self.golden_images): michael@0: local_url = "file:///" + file michael@0: local_url = re.sub(r"\\", "/", local_url) michael@0: print local_url michael@0: inner_html = self.tester.get_innerHTML_from_URL(local_url) michael@0: golden_inner_html = open(golden_image).read() michael@0: if inner_html != golden_inner_html: michael@0: failures += 1 michael@0: self.failUnless(failures == 0) michael@0: michael@0: def main(): michael@0: unittest.main() michael@0: michael@0: if __name__ == '__main__': michael@0: main()