16f61259448c2ff25b9055607f5888aca6f85ca4dmussa# Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
26f61259448c2ff25b9055607f5888aca6f85ca4dmussa# Use of this source code is governed by a BSD-style license that can be
36f61259448c2ff25b9055607f5888aca6f85ca4dmussa# found in the LICENSE file.
46f61259448c2ff25b9055607f5888aca6f85ca4dmussa
564350bd4622e01b78d83ce4b9953b3f392cdb4e0David Haddockimport logging
664350bd4622e01b78d83ce4b9953b3f392cdb4e0David Haddock
7988c6471aa8e8094135b7644438e9d28efd2992dDavid Haddockfrom autotest_lib.client.bin import utils
86f61259448c2ff25b9055607f5888aca6f85ca4dmussafrom autotest_lib.client.common_lib.cros import chrome
9f40b8e51b9325ea64b7cd890275c074f02697be5Prathmesh Prabhufrom autotest_lib.client.cros.cellular import test_environment
106f61259448c2ff25b9055607f5888aca6f85ca4dmussafrom autotest_lib.client.cros.ui import ui_test_base
116f61259448c2ff25b9055607f5888aca6f85ca4dmussafrom autotest_lib.client.common_lib import error
12514cae6d7d777889f33abffdf774c9fa76e4f2faTim Songfrom telemetry.util import image_util
136f61259448c2ff25b9055607f5888aca6f85ca4dmussa
146f61259448c2ff25b9055607f5888aca6f85ca4dmussaclass ui_SettingsPage(ui_test_base.ui_TestBase):
15ecef2f38ec267877f9b24a389ee9aa1435151dbaDavid Haddock    """
16ecef2f38ec267877f9b24a389ee9aa1435151dbaDavid Haddock    Collects screenshots of the settings page.
176f61259448c2ff25b9055607f5888aca6f85ca4dmussa    See comments on parent class for overview of how things flow.
186f61259448c2ff25b9055607f5888aca6f85ca4dmussa
196f61259448c2ff25b9055607f5888aca6f85ca4dmussa    """
206f61259448c2ff25b9055607f5888aca6f85ca4dmussa
216f61259448c2ff25b9055607f5888aca6f85ca4dmussa    def capture_screenshot(self, filepath):
226f61259448c2ff25b9055607f5888aca6f85ca4dmussa        """
23ecef2f38ec267877f9b24a389ee9aa1435151dbaDavid Haddock        Takes a screenshot of the settings page.
24ecef2f38ec267877f9b24a389ee9aa1435151dbaDavid Haddock
25ecef2f38ec267877f9b24a389ee9aa1435151dbaDavid Haddock        A mask is then drawn over the profile picture. This test runs only
26ecef2f38ec267877f9b24a389ee9aa1435151dbaDavid Haddock        on link at the moment so the dimensions provided are link specific.
276f61259448c2ff25b9055607f5888aca6f85ca4dmussa
28ecef2f38ec267877f9b24a389ee9aa1435151dbaDavid Haddock        Implements the abstract method capture_screenshot.
296f61259448c2ff25b9055607f5888aca6f85ca4dmussa
306f61259448c2ff25b9055607f5888aca6f85ca4dmussa        @param filepath: string, complete path to save screenshot to.
316f61259448c2ff25b9055607f5888aca6f85ca4dmussa
326f61259448c2ff25b9055607f5888aca6f85ca4dmussa        """
336f61259448c2ff25b9055607f5888aca6f85ca4dmussa        with chrome.Chrome() as cr:
346f61259448c2ff25b9055607f5888aca6f85ca4dmussa            tab = cr.browser.tabs[0]
35ecef2f38ec267877f9b24a389ee9aa1435151dbaDavid Haddock            tab.Navigate('chrome://settings')
366f61259448c2ff25b9055607f5888aca6f85ca4dmussa            tab.WaitForDocumentReadyStateToBeComplete()
376f61259448c2ff25b9055607f5888aca6f85ca4dmussa
386f61259448c2ff25b9055607f5888aca6f85ca4dmussa            if not tab.screenshot_supported:
396f61259448c2ff25b9055607f5888aca6f85ca4dmussa                raise error.TestError('Tab did not support taking screenshots')
406f61259448c2ff25b9055607f5888aca6f85ca4dmussa
41ecef2f38ec267877f9b24a389ee9aa1435151dbaDavid Haddock            screenshot = tab.Screenshot()
42ecef2f38ec267877f9b24a389ee9aa1435151dbaDavid Haddock            if screenshot is None:
43ecef2f38ec267877f9b24a389ee9aa1435151dbaDavid Haddock                raise error.TestFailure('Could not capture screenshot')
446f61259448c2ff25b9055607f5888aca6f85ca4dmussa
45ecef2f38ec267877f9b24a389ee9aa1435151dbaDavid Haddock            image_util.WritePngFile(screenshot, filepath)
466f61259448c2ff25b9055607f5888aca6f85ca4dmussa
47ecef2f38ec267877f9b24a389ee9aa1435151dbaDavid Haddock    def run_once(self, mask_points):
48f40b8e51b9325ea64b7cd890275c074f02697be5Prathmesh Prabhu        # Emulate a modem on the device.
49f40b8e51b9325ea64b7cd890275c074f02697be5Prathmesh Prabhu        test_env = test_environment.CellularPseudoMMTestEnvironment(
50f40b8e51b9325ea64b7cd890275c074f02697be5Prathmesh Prabhu                pseudomm_args=({'family': '3GPP'},),
51f40b8e51b9325ea64b7cd890275c074f02697be5Prathmesh Prabhu                use_backchannel=False,
52f40b8e51b9325ea64b7cd890275c074f02697be5Prathmesh Prabhu                shutdown_other_devices=False)
53f40b8e51b9325ea64b7cd890275c074f02697be5Prathmesh Prabhu
54f40b8e51b9325ea64b7cd890275c074f02697be5Prathmesh Prabhu        with test_env:
55f40b8e51b9325ea64b7cd890275c074f02697be5Prathmesh Prabhu            self.mask_points = mask_points
56f40b8e51b9325ea64b7cd890275c074f02697be5Prathmesh Prabhu
57f40b8e51b9325ea64b7cd890275c074f02697be5Prathmesh Prabhu            # Check if we should find mobile data in settings
58f40b8e51b9325ea64b7cd890275c074f02697be5Prathmesh Prabhu            # This should always return true now, since the modem is software
59f40b8e51b9325ea64b7cd890275c074f02697be5Prathmesh Prabhu            # emulated.
60f40b8e51b9325ea64b7cd890275c074f02697be5Prathmesh Prabhu            modem_status = utils.system_output('modem status')
61f40b8e51b9325ea64b7cd890275c074f02697be5Prathmesh Prabhu            if modem_status:
62f40b8e51b9325ea64b7cd890275c074f02697be5Prathmesh Prabhu                logging.info('Modem found')
63f40b8e51b9325ea64b7cd890275c074f02697be5Prathmesh Prabhu                logging.info(modem_status)
64f40b8e51b9325ea64b7cd890275c074f02697be5Prathmesh Prabhu                self.tagged_testname += '.mobile'
65f40b8e51b9325ea64b7cd890275c074f02697be5Prathmesh Prabhu            else:
66f40b8e51b9325ea64b7cd890275c074f02697be5Prathmesh Prabhu                logging.info('Modem not found')
67f40b8e51b9325ea64b7cd890275c074f02697be5Prathmesh Prabhu            self.run_screenshot_comparison_test()
68