2011-01-20 Dirk Pranke <dpranke@chromium.org>
authordpranke@chromium.org <dpranke@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 21 Jan 2011 02:30:55 +0000 (02:30 +0000)
committerdpranke@chromium.org <dpranke@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 21 Jan 2011 02:30:55 +0000 (02:30 +0000)
        Reviewed by Eric Seidel.

        nrwt: rewrite google_chrome_unittest to use mock filesystem.

        https://bugs.webkit.org/show_bug.cgi?id=52772

        * Scripts/webkitpy/layout_tests/port/google_chrome_unittest.py:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@76323 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/ChangeLog
Tools/Scripts/webkitpy/layout_tests/port/google_chrome_unittest.py

index 3e0526600085dffb438bb48e26339b4cd5673caa..35499914795bae35e33491c88571eb657a641fc3 100644 (file)
@@ -1,3 +1,13 @@
+2011-01-20  Dirk Pranke  <dpranke@chromium.org>
+
+        Reviewed by Eric Seidel.
+
+        nrwt: rewrite google_chrome_unittest to use mock filesystem.
+        
+        https://bugs.webkit.org/show_bug.cgi?id=52772
+        
+        * Scripts/webkitpy/layout_tests/port/google_chrome_unittest.py:
+
 2011-01-20  Dirk Pranke  <dpranke@chromium.org>
 
         Reviewed by Eric Siedel.
index 6539bb2b4beb98805aaf93d4314d060a44aa838a..aab8dd19941e5340ddd0ddb87de417128e6f942f 100644 (file)
 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-import codecs
-import os
 import unittest
 
-from webkitpy.common import newstringio
+from webkitpy.common.system import filesystem_mock
 
 import factory
 import google_chrome
@@ -58,45 +56,27 @@ class GetGoogleChromePortTest(unittest.TestCase):
         # be able to control the contents better.
 
         chromium_port = factory.get("chromium-mac")
-        chromium_overrides = chromium_port.test_expectations_overrides()
+        chromium_base = chromium_port.path_from_chromium_base()
+        fs = filesystem_mock.MockFileSystem()
         port = google_chrome.GetGoogleChromePort(port_name=port_name,
-                                                 options=None)
-
-        orig_exists = os.path.exists
-        orig_open = codecs.open
-        expected_string = "// hello, world\n"
-
-        def mock_exists_chrome_not_found(path):
-            if 'test_expectations_chrome.txt' in path:
-                return False
-            return orig_exists(path)
-
-        def mock_exists_chrome_found(path):
-            if 'test_expectations_chrome.txt' in path:
-                return True
-            return orig_exists(path)
-
-        def mock_open(path, mode, encoding):
-            if 'test_expectations_chrome.txt' in path:
-                return newstringio.StringIO(expected_string)
-            return orig_open(path, mode, encoding)
-
-        try:
-            os.path.exists = mock_exists_chrome_not_found
-            chrome_overrides = port.test_expectations_overrides()
-            self.assertEqual(chromium_overrides, chrome_overrides)
-
-            os.path.exists = mock_exists_chrome_found
-            codecs.open = mock_open
-            chrome_overrides = port.test_expectations_overrides()
-            if chromium_overrides:
-                self.assertEqual(chrome_overrides,
-                                 chromium_overrides + expected_string)
-            else:
-                self.assertEqual(chrome_overrides, expected_string)
-        finally:
-            os.path.exists = orig_exists
-            codecs.open = orig_open
+                                                 options=None, filesystem=fs)
+
+        expected_chromium_overrides = '// chromium overrides\n'
+        expected_chrome_overrides = '// chrome overrides\n'
+        chromium_path = fs.join(chromium_base, 'webkit', 'tools',
+                                'layout_tests', 'test_expectations.txt')
+        chrome_path = fs.join(chromium_base, 'webkit', 'tools',
+                              'layout_tests', 'test_expectations_chrome.txt')
+
+        fs.files[chromium_path] = expected_chromium_overrides
+        fs.files[chrome_path] = None
+        actual_chrome_overrides = port.test_expectations_overrides()
+        self.assertEqual(expected_chromium_overrides, actual_chrome_overrides)
+
+        fs.files[chrome_path] = expected_chrome_overrides
+        actual_chrome_overrides = port.test_expectations_overrides()
+        self.assertEqual(actual_chrome_overrides,
+                         expected_chromium_overrides + expected_chrome_overrides)
 
 
 if __name__ == '__main__':