import os

from telemetry.test import tab_test_case

class InspectorMemoryTest(tab_test_case.TabTestCase):
  def testGetDOMStats(self):
    unittest_data_dir = os.path.join(os.path.dirname(__file__),
                                     '..', '..', '..', 'unittest_data')
    self._browser.SetHTTPServerDirectories(unittest_data_dir)

    self._tab.Navigate(
      self._browser.http_server.UrlOf('dom_counter_sample.html'))
    self._tab.WaitForDocumentReadyStateToBeComplete()

    counts = self._tab.dom_stats
    self.assertEqual(counts['document_count'], 1)
    self.assertEqual(counts['node_count'], 14)
    self.assertEqual(counts['event_listener_count'], 2)

import os

from telemetry.test import tab_test_case

class InspectorMemoryTest(tab_test_case.TabTestCase):
  def testGetDOMStats(self):
    unittest_data_dir = os.path.join(os.path.dirname(__file__),
                                     '..', '..', '..', 'unittest_data')
    self._browser.SetHTTPServerDirectories(unittest_data_dir)

    # Due to an issue with CrOS, we create a new tab here rather than
    # using self._tab to get a consistent starting page on all platforms
    tab = self._browser.tabs.New()

    tab.Navigate(
      self._browser.http_server.UrlOf('dom_counter_sample.html'))
    tab.WaitForDocumentReadyStateToBeComplete()

    counts = tab.dom_stats
    self.assertEqual(counts['document_count'], 2)
    self.assertEqual(counts['node_count'], 18)
    self.assertEqual(counts['event_listener_count'], 2)

Fix InspectorMemoryTest.testGetDOMStats to have consistent behaviour on CrOS and desktop versions of Chrome. Starting the browser in CrOS requires navigating through an initial setup that does not leave us with a tab at "chrome://newtab". This workaround runs the test in a new tab on all platforms for consistency.
Fix InspectorMemoryTest.testGetDOMStats to have consistent
behaviour on CrOS and desktop versions of Chrome. Starting the
browser in CrOS requires navigating through an initial setup
that does not leave us with a tab at "chrome://newtab". This workaround
runs the test in a new tab on all platforms for consistency.

BUG=235634
TEST=InspectorMemoryTest.testGetDOMStats passes on cros and system
NOTRY=true

Review URL: https://chromiumcodereview.appspot.com/14672002

git-svn-id: de016e52bd170d2d4f2344f9bf92d50478b649e0@197490 0039d316-1c4b-4281-b951-d872f2087c98

  import os
  
  from telemetry.test import tab_test_case
  
  class InspectorMemoryTest(tab_test_case.TabTestCase):
    def testGetDOMStats(self):
      unittest_data_dir = os.path.join(os.path.dirname(__file__),
                                       '..', '..', '..', 'unittest_data')
      self._browser.SetHTTPServerDirectories(unittest_data_dir)
  
+     # Due to an issue with CrOS, we create a new tab here rather than
+     # using self._tab to get a consistent starting page on all platforms
+     tab = self._browser.tabs.New()
+ 
-     self._tab.Navigate(
+     tab.Navigate(
        self._browser.http_server.UrlOf('dom_counter_sample.html'))
-     self._tab.WaitForDocumentReadyStateToBeComplete()
+     tab.WaitForDocumentReadyStateToBeComplete()
  
-     counts = self._tab.dom_stats
+     counts = tab.dom_stats
-     self.assertEqual(counts['document_count'], 1)
+     self.assertEqual(counts['document_count'], 2)
-     self.assertEqual(counts['node_count'], 14)
+     self.assertEqual(counts['node_count'], 18)
      self.assertEqual(counts['event_listener_count'], 2)
  
Fix InspectorMemoryTest.testGetDOMStats to have consistent behaviour on CrOS and desktop versions of Chrome. Starting the browser in CrOS requires navigating through an initial setup that does not leave us with a tab at "chrome://newtab". This workaround runs the test in a new tab on all platforms for consistency.
## Code Before:
import os

from telemetry.test import tab_test_case

class InspectorMemoryTest(tab_test_case.TabTestCase):
  def testGetDOMStats(self):
    unittest_data_dir = os.path.join(os.path.dirname(__file__),
                                     '..', '..', '..', 'unittest_data')
    self._browser.SetHTTPServerDirectories(unittest_data_dir)

    self._tab.Navigate(
      self._browser.http_server.UrlOf('dom_counter_sample.html'))
    self._tab.WaitForDocumentReadyStateToBeComplete()

    counts = self._tab.dom_stats
    self.assertEqual(counts['document_count'], 1)
    self.assertEqual(counts['node_count'], 14)
    self.assertEqual(counts['event_listener_count'], 2)

## Instruction:
Fix InspectorMemoryTest.testGetDOMStats to have consistent behaviour on CrOS and desktop versions of Chrome. Starting the browser in CrOS requires navigating through an initial setup that does not leave us with a tab at "chrome://newtab". This workaround runs the test in a new tab on all platforms for consistency.
## Code After:
import os

from telemetry.test import tab_test_case

class InspectorMemoryTest(tab_test_case.TabTestCase):
  def testGetDOMStats(self):
    unittest_data_dir = os.path.join(os.path.dirname(__file__),
                                     '..', '..', '..', 'unittest_data')
    self._browser.SetHTTPServerDirectories(unittest_data_dir)

    # Due to an issue with CrOS, we create a new tab here rather than
    # using self._tab to get a consistent starting page on all platforms
    tab = self._browser.tabs.New()

    tab.Navigate(
      self._browser.http_server.UrlOf('dom_counter_sample.html'))
    tab.WaitForDocumentReadyStateToBeComplete()

    counts = tab.dom_stats
    self.assertEqual(counts['document_count'], 2)
    self.assertEqual(counts['node_count'], 18)
    self.assertEqual(counts['event_listener_count'], 2)
